简体   繁体   English

Flask NameError: while flask_wtf 和 FlaskForm

[英]Flask NameError: while flask_wtf and FlaskForm

I usually have no problem adding forms to flask pages however this time I'm really struggling to find the specific issue.我通常没有问题将 forms 添加到 flask 页面但是这次我真的很难找到具体问题。

Here are the details of my route:以下是我的路线的详细信息:

@app.route("/add_recipe")
def add_recipe():
    form = abcForm()
    return render_template('add_recipe.html', title="Recipe", form= form)

Here is my form class这是我的表格 class

class abcForm(FlaskForm):
    email = StringField('Email', validators=[DataRequired(), Email()])
    password = PasswordField('Password',validators=[DataRequired()])
    remember = BooleanField('Remember Me')
    submit = SubmitField('Login Up')

The error message I get is "NameError: name 'abcForm' is not defined"我收到的错误消息是“NameError: name 'abcForm' is not defined”

Check to see if you are importing your form class into your route file.检查您是否将表格 class 导入到您的路线文件中。

from form-file-name import abcForm

Another thing to check, in your jinja template are you referring to your form as 'abcForm' instead of 'form'?要检查的另一件事是,在您的 jinja 模板中,您是否将表单称为“abcForm”而不是“表单”? It should be 'form' in jinja since you save it into form in your route.它应该是 jinja 中的“表单”,因为您将它保存到您的路线中的表单中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM