我有一个Django formset,我希望使用bootstrap3显示内联,但我不断收到错误ManagementForm data is missing or has been tampered with
。我在我的html模板中包含了{{formset.management_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})
我使用的Django模板看起来像这样:
<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}}
标签,所以我不确定为什么Django告诉我它不存在。
感谢。