我正在尝试扩展基于烧瓶的项目http://hack4impact.github.io/flask-base/templates/。我有以下视图功能:
@login_required
@main.route('/cities', methods=['GET', 'POST'])
def cities():
if request.method =='POST':
print(request.data)
redirect('/selected')
cities_list = []
recordset = Postings.query.all()
for r in recordset:
city = str(r.city)
elapsed_hours = round((time.time() - int(r.datetime)) / 3600, 1)
cities_list.append(str(r.city) + '-' + str(r.email) + '-' + str(elapsed_hours))
form = PostingSelectForm()
form.posting.choices = [(item, item) for item in cities_list]
return render_template("main/cities.html",
form = form)
@login_required
@main.route('/selected')
def selected():
return 'ddd'
我正在使用宏来生成上述文档中描述的表单。宏被称为render_template,并且正常工作以生成我能够提交的表单。您可以在屏幕截图中看到提交的信息。但是我无法捕获行中的信息:
print(request.data)
redirect('/selected')
并且不会发生重定向。当我查看宏生成的wtf-form的html时。它始于;
<form action="" method="POST" enctype="" class="ui form
">
<div style="display:none;"><input id="csrf_token" name="csrf_token" type="hidden" value="1516882441##491001e55a57ceac4053b7937d21e61768f66d0b"></div>
所以我想知道这里是否缺少行动。我不知道“”的帖子是什么。此外,如果这是问题,我将如何修改我的表单以包含由此宏生成的给定操作。我的表单代码是:
class PostingSelectForm(Form):
posting = SelectField(
'posting',
choices=[('cpp', 'C++'), ('py', 'Python'), ('text', 'Plain Text')]
)
submit = SubmitField('Select')