Python Flask引导wtf.quick\u表单是否呈现SelectFields?
各位专家好: 我需要使用Python Flask引导wtf.quick\u表单是否呈现SelectFields?,python,flask,flask-wtforms,Python,Flask,Flask Wtforms,各位专家好: 我需要使用wtf.quick\u form 我正在尝试发布一个包含用户名、密码和角色字段的注册表。 用户名和密码是直接的文本字段。 角色是一个选择字段 我的表格是这样的 #------------------------------------------------------------------------------------------ class RegistrationForm(FlaskForm): #------------------------------
wtf.quick\u 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'))
{% 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 %}
我的Register.html如下所示
#------------------------------------------------------------------------------------------
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'))
{% 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 %}
{%extends“base.html”%}
{%import'bootstrap/wtf.html'作为wtf%}
{%block app_content%}
{{{('Register')}
{{wtf.quick_form(form)}
{%endblock%}
但是,输出不会将选择字段呈现为下拉列表。
它只显示一个项目('Manager'、'Stores'、'Sales'、'Engineer'、'QC'、'Vendor')
,并选择它,如下图所示
我查阅了WTForms文档,这些文档可以在上找到
看起来只有文本字段被渲染?还是我犯了什么错误?得到了答案:
我没有正确地形成答案选择
desiredRole = SelectField('Desired Role', choices=[(roleChoice, roleChoice) for roleChoice in roleChoices], default=1)
现在,代码输出正在呈现选择字段。快速提问:打印(角色扮演)的输出是什么?明白了!我没有正确地形成选择。请尝试添加您的修复,作为答案:D