当我尝试使用Flask-WTForms时,我按照以下步骤操作:
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)
然后我得到TypeError:类型'_RequestGlobals'的参数不可迭代。
这是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>
答案 0 :(得分:0)
这是由于您的视图功能的名称。只需更改名称即可。它应该工作正常。
@app.route('/test',methods=['GET','POST'])
def my_form(): # See this line
form = EmailPasswordForm()
return render_template('form.html',
title = 'Sign In',
form = form)