【发布时间】:2020-08-06 12:07:21
【问题描述】:
我正在使用 Django 2.2。
我正在创建一个动态表单(未绑定到模型)。我已经设法动态创建了多个表单输入(包括接受多个选择的输入),但是在创建选择(即下拉)表单输入元素时遇到了问题。
当我在模板中使用{{ form.as_p }} 呈现表单时,选择表单字段被呈现为复选框。
我已经尝试了ALL下面的语句,结果是一样的:表单输入字段仍然呈现为一个复选框。
form_field = CharField(label=the_label, widget=forms.Select(choices=CHOICES, required=is_required))
form_field = ChoiceField(label=the_label, choices=CHOICES, widget=Select, required=is_required)
form_field = ChoiceField(label=the_label, widget=Select(choices=CHOICES), required=is_required)
如何强制 django 将此字段呈现为选择(下拉)字段?
【问题讨论】:
标签: django