Question: Adjust html file so it greets the user: Hello (name) from (address)! {% extends bootstrap/base.html %} {% import bootstrap/wtf.html as wt %} {% block title
Adjust html file so it greets the user: "Hello (name) from (address)!"
{% extends "bootstrap/base.html" %} {% import "bootstrap/wtf.html" as wt %}
{% block title %}Flasky!{% endblock %}
{% block content %}
Hello, {% if name %}{{ name }}{% else %}Stranger{% endif %}!
{{ wtf.quick_form(form) }} {% endblock %}
(Here is the py file):
from flask import Flask, render_template, session, redirect, url_for
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
from flask_bootstrap import Bootstrap
app = Flask(__name__)
app.config['SECRET_KEY'] = 'hard to guess string'
bootstrap = Bootstrap(app)
class NameForm(FlaskForm):
name = StringField('What is your name?', validators=[DataRequired()])
submit = SubmitField('Submit')
@app.route('/', methods=['GET','POST'])
def index():
form=NameForm()
if form.validate_on_submit():
#we will set up a cookie to store the name
session['name']=form.name.data
#the redirect will help eliminate the refresh warning
return redirect(url_for('index'))
#the following line will get the saved name from the session cookie
return render_template('user5.html', form=form, name=session.get('name'))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
