首页新闻招聘找找看知识库

wtforms中表单验证失效

0
悬赏园豆:30 [待解决问题]
 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)

代码如上,访问网站,在输入框输入并提交后,name值无法被赋值

xiaoblue的主页 xiaoblue | 初学一级 | 园豆:115
提问于:2018-04-16 16:13
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册