Question
Adjust the following Python file so it also collects: - address - birthdate (prompt for the user to enter in this format: YYYY-MM-DD) - Similarly
Adjust the following Python file so it also collects:
- address
- birthdate (prompt for the user to enter in this format: YYYY-MM-DD)
- Similarly to how it handles name, it should store and get the above variables in the session cookie:
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started