如何通过另一个表单的submition输出formset?

时间:2018-02-21 15:36:46

标签: python django django-forms formset

我正在尝试输出formset作为同一页面上另一个表单提交的结果。

此formset包含应提交的表单。

这是我的功能视图:

def manage_articles(request):
    dyn_form = type('DynForm', 
                (forms.BaseForm,),
                {'base_fields': {'title': forms.CharField(), 'name': forms.CharField()}})


    form = ArticleForm()
    formset = formset_factory(dyn_form, extra=4)
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        formset = formset(request.POST, request.FILES)

        if formset.is_valid():
            print('Formset sent')
        if form.is_valid():
            return render(request, 'test_form.html', {'formset': formset, 'form':form})
    else:
        return render(request, 'test_form.html', {'form':form, 'formset': ''})

这是我的基本形式:

class ArticleForm(forms.Form):
    author = forms.CharField()

目前,我在提交第一张表格时收到错误:

['ManagementForm data is missing or has been tampered with']

我该怎么做?

0 个答案:

没有答案