[英]How to create check box in django
我正在开发django中的网站。我必须在模板中显示一个复选框。
我正在使用模型表格,
class ReportPersonForm(forms.ModelForm):
class Meta:
model = ReportPerson
fields = ['name','first_aid','sick_bay','ambulance']
我必须分别为以下字段创建复选框,first_aid,sick_bay,救护车和模板中的渲染。
任何人都可以帮我创建一个django检查以及如何设计模板来显示复选框。
谢谢
如果您将模型中的字段定义为BooleanFileld - 您可以使用
{{ form.first_aid }}
在你的模板
在您的表单文件中
class ReportPersonForm(forms.ModelForm):
first_aid = models.BooleanField()
sick_bay = models.BooleanField()
ambulance = models.BooleanField()
class Meta:
model = ReportPerson
fields = ['name','first_aid','sick_bay','ambulance']
然后,对于您的模板,您有多个选项,请在文档中阅读适合您需求的内容: 使用表单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.