如果userinput匹配特定值,我想重定向用户
@flask_class.route('/base', methods=['GET', 'POST'])
def startpoint():
form = FirstRiddleForm()
if form.validate_on_submit():
if form.useranswer.data == 'correct':
redirect(url_for('passedtest'))
else:
redirect(url_for('index'))
return render_template('base.html', form=form)
到目前为止,单击“提交”按钮时我没有任何响应(没有重定向。)
form.useranswer.data == 'correct'
是获得用户输入的正确方法吗?
表格
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
class FirstRiddleForm(FlaskForm):
useranswer = StringField("insert your answer", validators=[DataRequired()])
submitanswer = SubmitField("Submit")
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>startpoint</title>
</head>
<body>
<h1>your journey beginns here, Traveler !</h1><br>
<form action="" method="post" novalidate>
{{ form.hidden_tag() }}
<p>
{{ form.useranswer.label }}<br>
{{ form.useranswer(size=32) }}</p>
<p>
{{ form.submitanswer() }}</p>
</form>
</body>
</html>
答案 0 :(得分:0)
我相信您应该退还redirect()