You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
985 B

  1. from flask import Flask, render_template, session, redirect, url_for
  2. from flask_bootstrap import Bootstrap
  3. from flask_moment import Moment
  4. from flask_wtf import FlaskForm
  5. from wtforms import StringField, SubmitField
  6. from wtforms.validators import DataRequired
  7. app = Flask(__name__)
  8. app.config['SECRET_KEY'] = 'hard to guess string'
  9. bootstrap = Bootstrap(app)
  10. moment = Moment(app)
  11. class NameForm(FlaskForm):
  12. name = StringField('What is your name?', validators=[DataRequired()])
  13. submit = SubmitField('Submit')
  14. @app.errorhandler(404)
  15. def page_not_found(e):
  16. return render_template('404.html'), 404
  17. @app.errorhandler(500)
  18. def internal_server_error(e):
  19. return render_template('500.html'), 500
  20. @app.route('/', methods=['GET', 'POST'])
  21. def index():
  22. form = NameForm()
  23. if form.validate_on_submit():
  24. session['name'] = form.name.data
  25. return redirect(url_for('index'))
  26. return render_template('index.html', form=form, name=session.get('name'))