【问题标题】:ManagementForm data is missing or has been tampered Django FormTools WizardManagementForm 数据丢失或被篡改 Django FormTools Wizard
【发布时间】:2022-08-23 04:42:02
【问题描述】:

视图.py

FORMS = [(\"customer\", CustomerModelForm),
         (\"supplier\", SupplierModelForm),
         (\"brand\", BrandMasterModelForm)]


TEMPLATES = {\"customer\": \"add_customer.html\",
             \"supplier\": \"supplier_master\",
             \"brand\": \"add_brand.html\"}
        
class MultiStepWizard(SessionWizardView):
    def get_template_names(self):
        return [TEMPLATES[self.steps.current]]

    def done(self, form_list, **kwargs):
        form_data = [form.cleaned_data for form in form_list]
        return render(self.request, \"dashboard_inventory.html\", {\"data\":form_data})

网址.py

path(\'manage_sales/\', MultiStepWizard.as_view(FORMS), name=\"MultiStepWizard\")

表格.py

class CustomerModelForm(forms.ModelForm):
    class Meta:
        model = Customer
        fields = (\'name\',\'address\',\'contact\',\'email\',\'state\',\'gstin\',\'pan\')
        
class SupplierModelForm(forms.ModelForm):
    class Meta:
        model = Supplier
        fields = (\'name\',\'address\',\'city\',\'manager\',\'contact\')
        widgets = {
            \'name\':forms.TextInput(attrs={\'class\': \'form-control\'}),
            \'address\':forms.TextInput(attrs={\'class\': \'form-control\'}),
            \'city\':forms.TextInput(attrs={\'class\': \'form-control\'}),
            \'manager\':forms.TextInput(attrs={\'class\': \'form-control\'}),
            \'contact\':forms.TextInput(attrs={\'class\': \'form-control\'}),
            
            }

class BrandMasterModelForm(forms.ModelForm):
    class Meta:
        model = BrandMaster
        fields=(\'brand_name\', \'suppliername\')
        widgets={\'brand_name\':forms.TextInput(attrs={\'class\': \'form-control\'}),\'suppliername\':forms.Select(attrs={\'id\':\'choicewa\',\'class\': \'form-control\',\'required\': \'true\'}),

        }

我正在尝试使用 formtool 用我自己的模板保存多步表单。 但我收到错误

ManagementForm data is missing or has been tampered Django FormTools Wizard

保存第一个表单时,无法继续进行。

    标签: python django django-formtools


    【解决方案1】:

    您需要以 html 形式添加以下行

    {{ 向导.management_form }}

    【讨论】:

      猜你喜欢
      • 2014-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多