Skip to content
Myr

Fix Message Flashing doc, from SwashBuckla #pocoo.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Provide a full example as promised in the doc.

authored by Ron DuPlain · committed by Ron DuPlain · parent 36f3184 · Browse files · 1 file+10 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+10 added−2 removed

  • other:+10 added−2 removed

1 file+10 added−2 removed

modified:docs/patterns/flashing.rst+10 added-2 removed
14 unmodified lines
15---------------1617So here is a full example::1819 from flask import flash, redirect, url_for, render_template19 from flask import Flask, flash, redirect, render_template, \20 request, url_for2122 app = Flask(__name__)23 app.secret_key = 'some_secret'2425 @app.route('/')26 def index():27 return render_template('index.html')28
1 unmodified line
30 def login():31 error = None32 if request.method == 'POST':33 if request.form['username'] != 'admin' or \30 request.form['password'] != 'secret':34 request.form['password'] != 'secret':35 error = 'Invalid credentials'36 else:37 flash('You were successfully logged in')38 return redirect(url_for('index'))39 return render_template('login.html', error=error)4041 if __name__ == "__main__":42 app.run()434445And here the ``layout.html`` template which does the magic:4647.. sourcecode:: html+jinja48
103 unmodified lines