【发布时间】:2016-07-28 22:26:38
【问题描述】:
我正在尝试设置我的 Django 表单的初始值。但是,我无法做到。我尝试过使用 initial 并搜索了很多。
我的表单代码是
class xyz(forms.Form):
random_text = forms.CharField(label='random_label')
CHOICES=[(1,'abc'),
(2,'def')]
selection = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect())
我的模板代码是
<div class="text-center">
{% for choice in form.selection %}
<div class="radio-inline">
{{ choice }}
</div>
{% endfor %}
</div>
同样的视图代码是
form = xyz(request.GET)
【问题讨论】:
标签: django django-forms django-templates radio-button default