1 from flask import * 2 from flask_script import * 3 from flask_wtf import * 4 from wtforms import * 5 from wtforms.validators import * 6 from flask_wtf import * 7 8 app=Flask(__name__) 9 app.config['SECRET_KEY']='hardstring' 10 11 class NameForm(FlaskForm): 12 name=StringField('What\'s your name',validators=[InputRequired()]) 13 14 submit=SubmitField('Submit') 15 16 17 @app.route('/',methods=('GET', 'POST')) 18 def index(): 19 form=NameForm() 20 name=None 21 if form.validate_on_submit(): 22 name=form.name.data 23 form.name.data='' 24 return render_template('first.html',form=form,name=name) 25
代码如上,访问网站,在输入框输入并提交后,name值无法被赋值