FlaskBootstrap wtf.quick_表单是否呈现SelectFields?

2024-10-03 15:31:30 发布

您现在位置:Python中文网/ 问答频道 /正文

各位专家好:

我需要有关使用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'),并选择它,如下图所示

Code output

我查阅了https://pythonhosted.org/Flask-Bootstrap/forms.html上提供的WTForms文档

看起来只有文本字段被渲染?还是我犯了错误


Tags: 文本divformregister角色密码htmlmanager
1条回答
网友
1楼 · 发布于 2024-10-03 15:31:30

我得到了答案:

我没有正确地形成答案选择

desiredRole = SelectField('Desired Role', choices=[(roleChoice, roleChoice) for roleChoice in roleChoices], default=1)

现在,代码输出呈现选择字段

相关问题 更多 >