【发布时间】:2013-07-06 10:18:28
【问题描述】:
我的 Django 表单中有一个 BooleanField,我希望其初始值为 True,因此我将其定义为:
my_checkbox = forms.BooleanField(label='My Checkbox', help_text='Some help text here', initial=True)
在我的助手中,我有:
helper.layout = Layout(
Field('my_checkbox', template="custom.html")
Custom.html 看起来像:
<input class="checkboxinput" id="id_{{ field.name }}" name="{{ field.name }}" type="checkbox">
<span id="hint_id_{{ field.name }}" class="help-inline">{{ field.help_text }}</span>
我尝试输出 field.initial 的值,但没有任何显示。我知道,如果我手动编码,我会输入<input ... checked>,然后会选中该框。
有没有办法访问字段的“初始”部分并将其设置在我的自定义模板中?谢谢!
【问题讨论】:
标签: django django-forms django-crispy-forms