我正在 Django 中创建一个表单(使用 ModelForm)。 有很多复选框,我想让它必须选中其中一个才能提交表单。我指的不是任何一个复选框,而是一个特定 框。我在 Django 文档中找不到任何内容。任何帮助,将不胜感激。
最佳答案
有点像
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:需要勾选复选框以提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16988127/