Python Flask专家您好:
我需要使用wtf.quick_form呈现表单的帮助
我正在尝试发布一个具有用户名、密码和角色字段的注册表。用户名和密码是直接的文本字段。角色是一个选择字段。
我的表单如下所示
#------------------------------------------------------------------------------------------
class RegistrationForm(FlaskForm):
#------------------------------------------------------------------------------------------
yourName = StringField('Your Name', validators=[DataRequired()])
empId = StringField('Employee ID')
roleChoices = ('Manager', 'Stores', 'Sales', 'Engineer', 'QC', 'Vendor')
desiredRole = SelectField('Desired Role', choices=[(roleChoices, roleChoices)], default=1)
submit = SubmitField(_l('Register'))我的Register.html看起来像这样
{% extends "base.html" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% block app_content %}
<h1>{{ _('Register') }}</h1>
<div class="row">
<div class="col-md-4">
{{ wtf.quick_form(form) }}
</div>
</div>
{% endblock %}但是,输出不会将选择字段呈现为下拉列表。它只显示一个项目('Manager', 'Stores', 'Sales', 'Engineer', 'QC', 'Vendor')并选择它,如下图所示。
我查阅了https://pythonhosted.org/Flask-Bootstrap/forms.html上提供的WTForms文档。
看起来只渲染了文本字段?或者我犯了什么错误?
发布于 2020-07-05 22:39:54
得到了答案:
我没有正确地形成答案选择。
desiredRole = SelectField('Desired Role', choices=[(roleChoice, roleChoice) for roleChoice in roleChoices], default=1)现在,代码输出是呈现Select字段。
https://stackoverflow.com/questions/62741763
复制相似问题