Permalink
Browse files

redirect after submit

  • Loading branch information...
1 parent 7d92ba6 commit 37a62dc0dad9b04678539bef52a9853a812c1a29 @eleddy eleddy committed Jan 12, 2012
Showing with 20 additions and 3 deletions.
  1. +17 −0 README.rst
  2. +3 −3 src/noiselist/__init__.py
View
@@ -330,6 +330,23 @@ to see the repr version of this object. To show only the todo item, update hello
{% endfor %}
<ul>
+Redirect
+--------
+Last but not least, let's add a redirect so that when the user submits a form, they go back
+to the front page. In __init__.py::
+
+ from flask import redirect, url_for
+ ...
+ db.session.add(todo)
+ db.session.commit()
+ return redirect(url_for('index'))
+
+Note that the redirect here is saying to redirect the the url that the index function services!!!
+
+Homework
+--------
+Follow the rest of the tutorial at http://flask.pocoo.org/docs/quickstart to support multiple
+users.
More Info
---------
@@ -3,7 +3,7 @@
from flask import render_template
from model import TodoItem
from model import db
-
+from flask import redirect, url_for
class _DefaultSettings(object):
USERNAME = 'world'
@@ -31,8 +31,8 @@ def index():
def add_todo():
if 'todo_item' in request.form:
todo = TodoItem(description=request.form['todo_item'])
- db.session.add(todob)
+ db.session.add(todo)
db.session.commit()
- return "Got it!"
+ return redirect(url_for('index'))
return "Unknown Error"

0 comments on commit 37a62dc

Please sign in to comment.