Python Django表单集验证错误:缺少管理表单
我有一个Django表单集,我希望使用bootstrap3内联显示,但我不断收到错误Python Django表单集验证错误:缺少管理表单,python,django,Python,Django,我有一个Django表单集,我希望使用bootstrap3内联显示,但我不断收到错误ManagementForm数据丢失或被篡改。我在html模板中包含了{{{formset.management\u form}},因此我不确定为什么会出现此错误。有人能帮我吗 我的表单如下所示: class MasterForm(forms.Form): def __init__(self,*args,**kwargs): initial_date_start = kwargs.pop('initi
ManagementForm数据丢失或被篡改。我在html模板中包含了{{{formset.management\u form}}
,因此我不确定为什么会出现此错误。有人能帮我吗
我的表单如下所示:
class MasterForm(forms.Form):
def __init__(self,*args,**kwargs):
initial_date_start = kwargs.pop('initial_start')
initial_date_end = kwargs.pop('initial_end')
sc_arg_list = kwargs.pop('sc_arg_list')
sc_section_label = kwargs.pop('sc_section_label')
tt_arg_list = kwargs.pop('tt_arg_list')
tt_section_label = kwargs.pop('tt_section_label')
super(MasterForm,self).__init__(*args,**kwargs)
self.fields['WINDOW_START'].initial=initial_date_start
self.fields['WINDOW_END'].initial=initial_date_end
self.fields['sc_ID'].choices=sc_arg_list
self.fields['sc_ID'].label=sc_section_label
self.fields['scID'].choices=sc_arg_list
self.fields['scID'].label=sc_section_label
self.fields['tasktype'].choices=tt_arg_list
self.fields['tasktype'].label=tt_section_label
WINDOW_START = forms.CharField(required=True,label="WINDOW_START")
WINDOW_END = forms.CharField(required=True,label="WINDOW_END")
sc_ID = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple)
scID = forms.ChoiceField(required=True, widget=forms.RadioSelect)
tasktype = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple)
FormSet = formset_factory(MasterForm)
keys = {'initial_start':"1/2/2015",'initial_end':"1/20/2015",'sc_arg_list':sat_list,'sc_section_label':"Please Select A Satelite",'tt_arg_list':task_type,'tt_section_label':"Please Select Task Type"}
if request.method == 'POST':
formset = FormSet(request.POST,keys)
if(formset.is_valid()):
message = "Thank you"
for form in formset:
print form
form.save()
else:
message = "Something went wrong"
else:
formset = FormSet(keys)
return render(request, 'InterfaceApp/gantt_search.html', {'formset': formset})
<form action="/InterfaceApp/gantt_search/" method="post" class="form">
{{ formset.management_form }}
{% csrf_token %}
{% bootstrap_formset formset %}
{% buttons %}
<div class="text-center">
<span class="btn-group">
<button type="submit" class="btn btn-primary center-block" value="Submit" name="All_Planning">
{% bootstrap_icon "fire" %} All Planning
</button>
<button type="submit" class="btn btn-primary center-block" value="Submit" name="Ops_Only">
{% bootstrap_icon "filter" %} Ops Only
</button>
</span>
</div>
{% endbuttons %}
</div>
</form>
使用它的视图如下所示:
class MasterForm(forms.Form):
def __init__(self,*args,**kwargs):
initial_date_start = kwargs.pop('initial_start')
initial_date_end = kwargs.pop('initial_end')
sc_arg_list = kwargs.pop('sc_arg_list')
sc_section_label = kwargs.pop('sc_section_label')
tt_arg_list = kwargs.pop('tt_arg_list')
tt_section_label = kwargs.pop('tt_section_label')
super(MasterForm,self).__init__(*args,**kwargs)
self.fields['WINDOW_START'].initial=initial_date_start
self.fields['WINDOW_END'].initial=initial_date_end
self.fields['sc_ID'].choices=sc_arg_list
self.fields['sc_ID'].label=sc_section_label
self.fields['scID'].choices=sc_arg_list
self.fields['scID'].label=sc_section_label
self.fields['tasktype'].choices=tt_arg_list
self.fields['tasktype'].label=tt_section_label
WINDOW_START = forms.CharField(required=True,label="WINDOW_START")
WINDOW_END = forms.CharField(required=True,label="WINDOW_END")
sc_ID = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple)
scID = forms.ChoiceField(required=True, widget=forms.RadioSelect)
tasktype = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple)
FormSet = formset_factory(MasterForm)
keys = {'initial_start':"1/2/2015",'initial_end':"1/20/2015",'sc_arg_list':sat_list,'sc_section_label':"Please Select A Satelite",'tt_arg_list':task_type,'tt_section_label':"Please Select Task Type"}
if request.method == 'POST':
formset = FormSet(request.POST,keys)
if(formset.is_valid()):
message = "Thank you"
for form in formset:
print form
form.save()
else:
message = "Something went wrong"
else:
formset = FormSet(keys)
return render(request, 'InterfaceApp/gantt_search.html', {'formset': formset})
<form action="/InterfaceApp/gantt_search/" method="post" class="form">
{{ formset.management_form }}
{% csrf_token %}
{% bootstrap_formset formset %}
{% buttons %}
<div class="text-center">
<span class="btn-group">
<button type="submit" class="btn btn-primary center-block" value="Submit" name="All_Planning">
{% bootstrap_icon "fire" %} All Planning
</button>
<button type="submit" class="btn btn-primary center-block" value="Submit" name="Ops_Only">
{% bootstrap_icon "filter" %} Ops Only
</button>
</span>
</div>
{% endbuttons %}
</div>
</form>
我使用的Django模板如下所示:
class MasterForm(forms.Form):
def __init__(self,*args,**kwargs):
initial_date_start = kwargs.pop('initial_start')
initial_date_end = kwargs.pop('initial_end')
sc_arg_list = kwargs.pop('sc_arg_list')
sc_section_label = kwargs.pop('sc_section_label')
tt_arg_list = kwargs.pop('tt_arg_list')
tt_section_label = kwargs.pop('tt_section_label')
super(MasterForm,self).__init__(*args,**kwargs)
self.fields['WINDOW_START'].initial=initial_date_start
self.fields['WINDOW_END'].initial=initial_date_end
self.fields['sc_ID'].choices=sc_arg_list
self.fields['sc_ID'].label=sc_section_label
self.fields['scID'].choices=sc_arg_list
self.fields['scID'].label=sc_section_label
self.fields['tasktype'].choices=tt_arg_list
self.fields['tasktype'].label=tt_section_label
WINDOW_START = forms.CharField(required=True,label="WINDOW_START")
WINDOW_END = forms.CharField(required=True,label="WINDOW_END")
sc_ID = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple)
scID = forms.ChoiceField(required=True, widget=forms.RadioSelect)
tasktype = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple)
FormSet = formset_factory(MasterForm)
keys = {'initial_start':"1/2/2015",'initial_end':"1/20/2015",'sc_arg_list':sat_list,'sc_section_label':"Please Select A Satelite",'tt_arg_list':task_type,'tt_section_label':"Please Select Task Type"}
if request.method == 'POST':
formset = FormSet(request.POST,keys)
if(formset.is_valid()):
message = "Thank you"
for form in formset:
print form
form.save()
else:
message = "Something went wrong"
else:
formset = FormSet(keys)
return render(request, 'InterfaceApp/gantt_search.html', {'formset': formset})
<form action="/InterfaceApp/gantt_search/" method="post" class="form">
{{ formset.management_form }}
{% csrf_token %}
{% bootstrap_formset formset %}
{% buttons %}
<div class="text-center">
<span class="btn-group">
<button type="submit" class="btn btn-primary center-block" value="Submit" name="All_Planning">
{% bootstrap_icon "fire" %} All Planning
</button>
<button type="submit" class="btn btn-primary center-block" value="Submit" name="Ops_Only">
{% bootstrap_icon "filter" %} Ops Only
</button>
</span>
</div>
{% endbuttons %}
</div>
</form>
{{formset.management_form}
{%csrf_令牌%}
{%bootstrap_formset formset%}
{%buttons%}
{%bootstrap_图标“fire”}所有计划
{%bootstrap_图标“过滤器”%}仅限操作
{%endbuttons%}
我没有丢失{{formset.management\u form}}
标记,所以我不确定Django为什么告诉我它不在那里
谢谢。我相信问题与此帖子非常相似: