Django form validation error: form control missing

I have a Django formset that I want to display inline using bootstrap3, but I keep getting the error ManagementForm data is missing or has been tampered with

. I have included {{formset.management_form}}

html in my template so dont know why I am getting this error. Can anyone help me?

My form looks like this:

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)

      

The view that uses it looks like this:

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})

      

And the Django template I'm using looks like this:

    <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>

      

I'm not missing the tag {{formset.management_form}}

, so I'm not sure why Django is telling me it's not there.

Thank.

+3


source to share





All Articles