Django 所有字段都指定此字段为必填错误

Django 所有字段都指定此字段为必填错误,django,forms,required,Django,Forms,Required,当我提交此表单时&所有字段都正确填充,form.is _valid()返回false&所有字段都给出:此字段是必需的错误,即使是CharField 有人能看出来是怎么回事吗? 这是我的表格: class TemplateConfiguredForm(forms.Form): """This form represents the TemplateConfigured Form""" template = forms.ChoiceField(widget=forms.Select(

当我提交此表单时&所有字段都正确填充,form.is _valid()返回false&所有字段都给出:此字段是必需的错误,即使是CharField

有人能看出来是怎么回事吗? 这是我的表格:

class TemplateConfiguredForm(forms.Form):
    """This form represents the TemplateConfigured Form"""
    template = forms.ChoiceField(widget=forms.Select(attrs={'id':'TemplateChoice'}))
    logo = forms.ImageField( widget = forms.FileInput(attrs={'id': 'inputLogo'}))
    image = forms.ImageField(widget = forms.FileInput(attrs={'id': 'inputImage'}))
    message = forms.CharField(widget = forms.Textarea(attrs={'id': 'inputText', 'rows':5, 'cols':25}))

    def __init__(self, custom_choices=None, *args, **kwargs):
        super(TemplateConfiguredForm, self).__init__(*args, **kwargs)

        r = requests.get('http://127.0.0.1:8000/sendMails/api/templates/?format=json')
        json = r.json()

        custom_choices=( ( template['url'], template['name']) for template in json)

        if custom_choices:
            self.fields['template'].choices = custom_choices
这是我的模板:

<form id="template_form"  method="post" role="form"  enctype="multipart/form-data" action="{% url 'create_templates' %}" >
 {% csrf_token %}

{{ form.as_p }}

    {% buttons %}
    <input type="submit"  value="Save Template"/>
  {% endbuttons %}



</form>

您在表单中传递的数据,如下所示:

form = TemplateConfiguredForm(request.POST, request.FILES)
由签名的第一个关键字参数捕获:

def __init__(self, custom_choices=None, *args, **kwargs):

删除您在表单中传递的数据,此处:

form = TemplateConfiguredForm(request.POST, request.FILES)
由签名的第一个关键字参数捕获:

def __init__(self, custom_choices=None, *args, **kwargs):

删除
custom\u choices=None

您已经更改了表单的签名,因此第一个位置参数是
custom\u choices
。不要那样做

您似乎根本没有从您的视图中传递该值,因此您可能应该完全删除它。但如果您确实需要它,您应该从kwargs目录中获取:

def __init__(self, *args, **kwargs):
    custom_choices = kwargs.pop('custom_choices')
    super(TemplateConfiguredForm, self).__init__(*args, **kwargs)

您已更改表单的签名,因此第一个位置参数是
自定义\u选项
。不要那样做

您似乎根本没有从您的视图中传递该值,因此您可能应该完全删除它。但如果您确实需要它,您应该从kwargs目录中获取:

def __init__(self, *args, **kwargs):
    custom_choices = kwargs.pop('custom_choices')
    super(TemplateConfiguredForm, self).__init__(*args, **kwargs)