我的POST发送了所选择的RadioField的数据,但在Flask中,我只得到“无”。对于form.display.data
。当我点击“提交”时,GET工作正常,并且RadioField会出现在页面上。显示变量在POST中以正确的选择发送。
如何获取POST的实际数据?
views.py
class Items(SimpleFormView):
route_base = "/manage"
datamodel = SQLAInterface(TerminalA82)
message = "Please make a seslection"
form = List_Items()
myList = Controller.generate #<-- external function provides list
form.display.choices = myList
@expose('/manage', methods=['GET'])
@has_access
def this_form_get(self):
return self.render_template('list_items.html', param1='Items', form=self.form)
@expose('/manage', methods=['POST'])
@has_access
def this_form_post(self):
return self.render_template('blank.html', param1=str(self.form.display.data))
POST呈现&#39;无&#39;在页面上。
forms.py
class List_Items(Form):
display = RadioField('Items', choices=[], coerce=int)
list_items.html(模板)
{% extends "appbuilder/base.html" %}
{% block content %}
<h3>{{param1}}</h3>
<form method="post">
{{ form.display }}
<input type="submit" value="Submit">
</form>
{% endblock %}
myList内容
>>> print myList
[('5', 'MyBAsic'), ('9', 'Cloudtest'), ('12', 'Test2'), ('15', 'NHLS-Test'), ('18', 'HSRC-Test')]
>>>
blank.html
{% extends "appbuilder/base.html" %}
{% block content %}
<p>{{param1}}</p>
{% endblock %}
答案 0 :(得分:1)
是的,如果您看到flask文档,那么您需要以request.form['Items']
而不是form.display.data
访问该数据。