我很难在提交时在一个烧瓶应用程序的WTForms页面中获取当前选择的项目。这个表格选择器数据无论在SelectField中选择了哪个项,value在提交时总是等于1(所有选项都有一个从1到10的惟一表id,格式为(1,'table_name'),其中1是一个整数。在
以下是当前代码:
在视图.py在
from flask import session
def view(self):
form = Tableset(request.form)
if request.method == 'POST' and form.validate():
#form.tableselector.data always returns 1 no matter which item is selected?
session['table_id'] = form.tableselector.data
在表单.py在
^{pr2}$在表格视图.html在
<form role="form" action="{{ url_for('app.table_view') }}" method="post">
{{ form.csrf_token }}
<div class="form-group">
{{ form.tableselector.label }}
{{ form.tableselector }}
</div>
我注意到在调试表单时,wtf Meta object csrf属性等于True,所以我知道csrf正在工作。在
问题是我在视图中调用了错误的参数。在
请看这里:How to obtain values of request variables using Python and Flask
使用:
相关问题 更多 >
编程相关推荐