Leoxu
Leoxu

Reputation: 31

Flask argument of type '_RequestGlobals' is not iterable

When I tried to use Flask-WTForms, I followed these steps:

from flask_wtf import Form
from wtforms import StringField, PasswordField
from wtforms.validators import DataRequired, Email

class EmailPasswordForm(Form):
    email = StringField('Email', validators=[DataRequired(), Email()])
    password = PasswordField('Password', validators=[DataRequired()])

@app.route('/form',methods=['GET','POST'])
def email_form():
    form = EmailPasswordForm()
    return render_template('form.html',
       title = 'Sign In',
       form = form)

then I get TypeError: argument of type '_RequestGlobals' is not iterable.

Here is the form.html:

<html>
<head>
    <title>Login Page</title>
</head>
<body>
    <form action="{{ url_for("form") }}" method="POST">
        <input type="text" name="email" />
        <input type="password" name="password" />
        {{ form.csrf_token }}
    </form>
</body>

Upvotes: 0

Views: 789

Answers (1)

Nabin
Nabin

Reputation: 11776

This is due to the name of your view function. Just change its name. It should work fine.

@app.route('/test',methods=['GET','POST'])
def my_form(): # See this line
    form = EmailPasswordForm()
    return render_template('form.html',
       title = 'Sign In',
       form = form)

Upvotes: 1

Related Questions