-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.py
33 lines (26 loc) · 1.19 KB
/
hello.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from flask import Flask, render_template, session, redirect, url_for, flash
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from datetime import datetime
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
from wtforms.validators import Email
class Form(FlaskForm):
name = StringField('What is your name?', validators=[DataRequired()])
email = StringField('What is your UofT Email address?', validators=[DataRequired(), Email("Please include an @ in the email address.")])
submit = SubmitField('Submit')
app = Flask(__name__)
bootstrap = Bootstrap(app)
app.config['SECRET_KEY'] = 'random string'
@app.route('/', methods=['GET', 'POST'])
def index():
form = Form()
if form.validate_on_submit():
previous_name = session.get('name')
if previous_name is not None and previous_name != form.name.data:
flash('Looks like you have changed your name!')
session['name'] = form.name.data
session['email'] = form.email.data
return redirect(url_for('index'))
return render_template('index.html', form=form, name=session.get('name'), email=session.get('email'))