wtforms 只返回 None [英] wtforms returns only None
问题描述
我有以下 HTML、CSS 和 JS 代码.但是,当我从右上角使用搜索并按回车键时.Flask 只会得到无"和搜索中输入的内容.
I have the following HTML, CSS and JS code. However, when I use the search from the top right side and press enter. Flask only get "None" and what was typed in search.
这是搜索的路线:
@app.route("/quick_search/", methods=("GET", "POST"))
@app.route("/quick_search/<property_id>")
def quick_search(property_id=None):
form = QuickSearch()
print "???", form.propert_name.data
和这个表单类:
from flask.ext.wtf import Form
from wtforms import SelectField, StringField, IntegerField, SelectMultipleField
class QuickSearch(Form):
propert_name = StringField()
为什么我只从 form.propert_name.data
得到 None
?
Why I only get None
from form.propert_name.data
?
推荐答案
您在 WTForms 实例和 Flask 视图中为您的字段命名 propert_name
.但在 HTML 中,它被称为 quick_search
.
You name your field propert_name
in the WTForms instance and in the Flask view. But in the HTML it is called quick_search
.
您还可以在 input
标签中两次使用属性 type
.你说 type="text"
然后你将 type
重新定义为 submit
稍后.这不应该导致问题,但值得照顾......
You also use the attribute type
twice in the input
tag. You say type="text"
and then you redefine type
to submit
later on. This shouldn't cause the problem, but worth it to take care…
这篇关于wtforms 只返回 None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!