django中具有django形式的预选复选框 [英] pre-selected checkbox in django with django forms
本文介绍了django中具有django形式的预选复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Django
中显示预选的复选框:
Am trying to display a pre-selected checkbox in Django
:
option = forms.BooleanField(required=False, initial=True)
,但复选框
显示为未选中状态.我正在使用 django 1.3 beta
.我在这里想念什么吗?
but the checkbox
shows up un-checked. Am using django 1.3 beta
. Am I missing something here ?
推荐答案
import django
from django import forms
class MyForm(forms.Form):
option = forms.BooleanField(required=False, initial=True)
>>>print MyForm()
<tr><th><label for="id_option">Option:</label></th><td><input checked="checked" type="checkbox" name="option" id="id_option" /></td></tr>
>>> django.VERSION
(1, 3, 0, 'beta', 1)
>>>
如您所见,checked ="checked"已正确设置.
As you can see the checked="checked" is properly set.
确定要不要使用onload javascript修改某些内容?
Are you sure you are not modifying something with onload javascript ?
这篇关于django中具有django形式的预选复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文