我创建了一个简单的水瓶WTF表单
class SequenceForm(Form):
sequence = StringField('Please enter a sequence in FASTA format', validators=[Required()])
submit = SubmitField('Submit')我已经设置了一条路线让它出现在页面上
@main.route('/bioinformatics')
def bioinformatics():
form = SequenceForm()
return render_template('bioinformatics.html', form=form)(到目前为止)一切都很好。当我将浏览器指向foo/生物信息学时,我会看到一个SequenceForm呈现的页面。但是,当我点击Submit按钮时,我总是被带回到@main.route('/')定义的根页面。
我怎样才能让提交按钮带我去其他地方?我想使用validate_on_submit()来处理表单中输入的数据。
谢谢!
/Michael Knudsen
更新(来自bioinformatics.html的代码)
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block title %}Bioinformatics{% endblock %}
{% block page_content %}
<div class="page-header">
<h1>Hello, Bioinformatics!</h1>
</div>
{{ wtf.quick_form(form) }}
{% endblock %}发布于 2015-06-26 08:32:29
您需要在html中以表单指定操作。
<form action="/url_which_handles_form_data" method="Post">
your code
</form>如果您正在使用蓝图,请确保给出正确的路径。
编辑:
我从bootstrap/templates/bootstrap/wtf.html那里找到了这个部分。
{% macro quick_form(form,
action="",
method="post",
extra_classes=None,
role="form",
form_type="basic",
horizontal_columns=('lg', 2, 10),
enctype=None,
button_map={},
id="") %}所以你可以打电话给
{{ wtf.quick_form(form, action="/fancy_url") }}或
{{ wtf.quick_form(form, action=url_for("blueprint_name.fancy_url")) }}取决于视图的位置。
发布于 2015-06-26 08:49:36
感谢和Zyber。我结合了您的建议,提出了以下解决方案。
我在路由的方法中添加了GET和POST
@main.route('/bioinformatics', methods=['GET', 'POST'])
def bioinformatics():
form = SequenceForm()
return render_template('bioinformatics.html', form=form)然后,我将wtf.quick_form调用封装在标记中。
<form action="{{ url_for('main.bioinformatics') }}" method="POST">
{{ wtf.quick_form(form) }}
</form> 现在一切都运转得很好。谢谢!
https://stackoverflow.com/questions/31068422
复制相似问题