Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <body>
- <h1>Login</h1>
- {% if error %}
- <p><strong>Error:</strong> {{ error }}
- {% endif %}
- <form action = "" method = post>
- <dl>
- <dt>Username:</dt>
- <dd>
- <input type = text name = username
- value = "{{request.form.username }}">
- </dd>
- <dt>Password:</dt>
- <dd><input type = password name = password></dd>
- </dl>
- <p><input type = submit value = Login></p>
- </form>
- </body>
- </html>
- <!doctype html>
- <html>
- <head>
- <title>Flask Message flashing</title>
- </head>
- <body>
- {% with messages = get_flashed_messages() %}
- {% if messages %}
- <ul>
- {% for message in messages %}
- <li<{{ message }}</li>
- {% endfor %}
- </ul>
- {% endif %}
- {% endwith %}
- <h1>Flask Message Flashing Example</h1>
- <p>Do you want to <a href = "{{ url_for('login') }}">
- <b>log in?</b></a></p>
- </body>
- </html>
- from flask import Flask, flash, redirect, render_template, request, url_for
- app = Flask(__name__)
- app.secret_key = 'random string'
- @app.route('/')
- def index():
- return render_template('index.html')
- @app.route('/login', methods = ['GET', 'POST'])
- def login():
- error = None
- if request.method == 'POST':
- if request.form['username'] != 'admin' or
- request.form['password'] != 'admin':
- error = 'Invalid username or password. Please try again!'
- else:
- flash('You were successfully logged in')
- return redirect(url_for('index'))
- return render_template('login.html', error = error)
- if __name__ == "__main__":
- app.run(debug = True)
Add Comment
Please, Sign In to add comment