使模型形式酥脆

时间:2014-02-07 03:10:20

标签: python django django-crispy-forms

我正在尝试显示所有模型项,但添加了一些脆弱的元素。然而,它在模型表单字段上方显示我的html和按钮,而不是在html下面和按钮上方。

表格

class BusinessForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(BusinessForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        self.helper.form_class = 'form-horizontal'
        self.helper.form_action = 'update'
        self.helper.form_method = 'post'
        self.helper.layout = Layout(
            HTML("<p class='alert-info alert'>Please confirm your business contact information is updated and correct.</p>"),
            Div(
                FormActions(
                    Submit('save_changes', 'Save changes', css_class="btn-primary"),
                ),
                css_class='row-fluid'
            )
        )

        # self.helper.add_input(Submit('save_changes', 'Save changes', css_class="btn-primary"))

    class Meta:
        model = Business
            exclude = ('inactive',)

查看

def index(request, token):
    try:
        business = Business.objects.get(token__token=token)
    except Token.DoesNotExist:
        business = None
    except Business.DoesNotExist:
        business = None

    return render(request, 'business/index.html', {'form': BusinessForm(instance=business)})

我看到了use Crispy form with ModelForm然而它在结构下方显示了我的模型字段,我甚至尝试了add_input做了同样的事情。如何让我的模型表单字段显示在alert-info和提交按钮之上?

0 个答案:

没有答案
相关问题