【发布时间】:2013-04-11 04:57:16
【问题描述】:
forms.py 是
class ShowlivereportForm(forms.Form):
livereport = forms.BooleanField()
如何创建 django 复选框
我不知道如何创建一个显示复选框的模板,谁能给我一个例子
【问题讨论】:
标签: python django django-models checkbox django-forms
forms.py 是
class ShowlivereportForm(forms.Form):
livereport = forms.BooleanField()
如何创建 django 复选框
我不知道如何创建一个显示复选框的模板,谁能给我一个例子
【问题讨论】:
标签: python django django-models checkbox django-forms
您可以在模板中使用 django 的自动 as_p 函数,或者您可以手动编写模板(以更好地控制其属性)。
对于自动你需要在你的模板中:
{{ form.as_p }}
对于手册,您应该使用以下内容:
<input type="checkbox" id="livereport" name="livereport" {% if form.livereport.value %}checked="checked"{% endif %}>
<label for="livereport">Show live report</label>
【讨论】:
form 作为render 函数的参数传递,它会起作用。查看此页面docs.djangoproject.com/en/dev/topics/forms 并查看示例。