Browse Source

Chapter 4: Redirects and user sessions (4b)

master
T. Meissner 6 years ago
parent
commit
b79829c006
1 changed files with 4 additions and 5 deletions
  1. +4
    -5
      hello.py

+ 4
- 5
hello.py View File

@ -1,4 +1,4 @@
from flask import Flask, render_template
from flask import Flask, render_template, session, redirect, url_for
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from flask_wtf import FlaskForm
@ -30,9 +30,8 @@ def internal_server_error(e):
@app.route('/', methods=['GET', 'POST'])
def index():
name = None
form = NameForm()
if form.validate_on_submit():
name = form.name.data
form.name.data = ''
return render_template('index.html', form=form, name=name)
session['name'] = form.name.data
return redirect(url_for('index'))
return render_template('index.html', form=form, name=session.get('name'))

Loading…
Cancel
Save