Question: Hello my code is showing some errors I need some help fixing it. I am not getting itt from flask import Flask, render_template from flask_bootstrap

Hello my code is showing some errors I need some help fixing it. I am not getting itt

from flask import Flask, render_template

from flask_bootstrap import Bootstrap

from flask_wtf import FlaskForm

from wtforms import StringField, SubmitField

from wtforms.validators import Required

from data import ACTORS

app = Flask(__name__)

# Flask-WTF requires an enryption key - the string can be anything

app.config['SECRET_KEY'] = 'some?bamboozle#string-foobar'

# Flask-Bootstrap requires this line

Bootstrap(app)

# this turns file-serving to static, using Bootstrap files installed in env

# instead of using a CDN

app.config['BOOTSTRAP_SERVE_LOCAL'] = True

# with Flask-WTF, each web form is represented by a class

# "NameForm" can change; "(FlaskForm)" cannot

# see the route for "/" and "index.html" to see how this is used

class NameForm(FlaskForm):

name = StringField('Which actor is your favorite?', validators=[Required()])

submit = SubmitField('Submit')

# define functions to be used by the routes (just one here)

# retrieve all the names from the dataset and put them into a list

def get_names(source):

names = []

for row in source:

name = row["name"]

names.append(name)

return sorted(names)

# all Flask routes below

# two decorators using the same f..;@app.route('/', methods=['GET', '..;@app.route('/index.html', 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 = ""

if form.validate_on_submit():

name = form.name.data

if name in names:

message = "Yay! " + name + "!"

# empty the form field

form.name.data = ""

else:

message = "That actor is not in our database."

# notice that we don't need to pass name or names to the template

return render_template('index.html', form=form, message=message)

# keep this as is

if __name__ == '__main__':

app.run(debug=True)

this is the repl.it link https://repl.it/join/bnghwukf-lekanbakare12

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!