实例化了一个Form 提示我没法使用validate_on_submit()这个函数,也不知道是哪儿的问题。
Form其他的正常,也能渲染出来
class AddlhForm(Form):
"""docstring for addlh"""
name = TextField('名称',[validators.Required()])
deduction = IntegerField('扣分')
submit = SubmitField('submit')
@app.route('/addlh', methods=['GET', 'POST'])
def addlh():
form = AddlhForm(request.form)
if form.validate_on_submit():
name = form.name.data
deduction = form.deduction.data
form.name.data = ''
form.deduction.data = ''
lh = Liangh(name, deduction)
db.session.add(lh)
db.session.commit()
return render_template('addlh.html', form=form)
<form method="POST" action="/addlh" class="pure-form">
<div class="getstu left">
<div>
<span>{{ form.name.label }}</span>
<span>{{ form.name() }}</span>
</div>
<div>
<span>{{ form.deduction.label }}</span>
<span>{{ form.deduction() }}</span>
</div>
{{form.submit()}}
</div>
</form>
然后就会报错
AttributeError
AttributeError: 'AddlhForm' object has no attribute 'validate_on_submit'
看看你引入的form对不对,有可能你是这样引入的
这里第二行的Form会顶替掉第一个wtf的form,所以你可能一直在用wtforms里的form,导致你的form没有validate_on_submit