0

I usually have no problem adding forms to flask pages however this time I'm really struggling to find the specific issue.

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 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"

1
  • You should show us the complete code, incl import statements. Also, when does the error occour? Commented Apr 7, 2021 at 19:02

1 Answer 1

1

Check to see if you are importing your form class into your route file.

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'? It should be 'form' in jinja since you save it into form in your route.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Andrew, I was not importing the form class into the route file. This is now fixed thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.