Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions