Skip to content

Commit

Permalink
Fix Message Flashing doc, from SwashBuckla #pocoo.
Browse files Browse the repository at this point in the history
Provide a full example as promised in the doc.
  • Loading branch information
rduplain committed Jan 31, 2012
1 parent 36f3184 commit 5cb50a4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docs/patterns/flashing.rst
Expand Up @@ -16,7 +16,11 @@ Simple Flashing

So here is a full example::

from flask import flash, redirect, url_for, render_template
from flask import Flask, flash, redirect, render_template, \
request, url_for

app = Flask(__name__)
app.secret_key = 'some_secret'

@app.route('/')
def index():
Expand All @@ -27,13 +31,17 @@ So here is a full example::
error = None
if request.method == 'POST':
if request.form['username'] != 'admin' or \
request.form['password'] != 'secret':
request.form['password'] != 'secret':
error = 'Invalid credentials'
else:
flash('You were successfully logged in')
return redirect(url_for('index'))
return render_template('login.html', error=error)

if __name__ == "__main__":
app.run()


And here the ``layout.html`` template which does the magic:

.. sourcecode:: html+jinja
Expand Down

0 comments on commit 5cb50a4

Please sign in to comment.