builtins.TypeError TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

提交表单出现该错误:

builtins.TypeError

TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

代码如下:

from flask import Flask, render_template
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from datetime import datetime
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired

class NameForm(FlaskForm):
    name   = StringField('what is your name', validators=[DataRequired])#错误就在这里
    submit = SubmitField('Submit')

@app.route('/', methods=['GET', 'POST'])
def formtest():
    name = None
    form = NameForm()
    if form.validate_on_submit():
        name = form.name.data
        form.name.data = ''
    return render_template('index.html', form=form, name=name)

wtforms的验证功能函数是个函数!!!!改成这样就好了!真的是一个超级低级的错误!


class NameForm(FlaskForm):
    name   = StringField('what is your name', validators=[DataRequired()])#错误就在这里
    submit = SubmitField('Submit')

 

你可能感兴趣的:(Flask)