from flask import Flask, render_template, redirect, url_for from flask_bootstrap import Bootstrap5 from flask_wtf import FlaskForm, CSRFProtect from wtforms import StringField, SubmitField from wtforms.validators import DataRequired, Length import secrets foo = secrets.token_urlsafe(16) app.secret_key = foo class nameForm(FlaskForm): name = StringField('Favorite actor?'), validators=[DataRequired), Length(10,40)]) submit = SubmitField('Submit') @app.route('/', methods=['GET', 'POST']) def index(): names = get_names(ACTORS) # you must tell the variable 'form' what you named #the class, above # 'form' is the variable name used in this template: #index.html form = NameForm() message = "" iv (form.validate_on_submit()): name = form.name.data if name.lower() in names: #empty the form field form.name.data = "" id = get_id(ACTORS, name) # redirect the browser to another route and template return redirect( url_for('actor', id=id) ) else: message = "That actor is not in our database." return render_template('index.html', names=names, form=form, message=message)