您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – Django:要求勾选复选框以提交表格

5b51 2022/1/14 8:20:27 python 字数 1294 阅读 453 来源 www.jb51.cc/python

我正在Django中创建一个表单(使用ModelForm). 有许多复选框,我想这样做,以便必须选择其中一个以提交表单.我不是指任何一个复选框,而是一个特定的框.我在Django文档中找不到任何内容.任何帮助,将不胜感激. 就像是 from django import forms class MyForm(forms.Form): check = forms.BooleanField(re

概述

from django import forms
class MyForm(forms.Form):
    check = forms.BooleanField(required = True)
    # your other form fields

对于BooleanField,required = True将检查是否选中该框.这是因为只有选中后才会提交数据.

资料来源:https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.BooleanField

Validates that the value is True (e.g. the check Box is checked) if the field has required=True.

总结

以上是编程之家为你收集整理的python – Django:要求勾选复选框以提交表格全部内容,希望文章能够帮你解决python – Django:要求勾选复选框以提交表格所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶