在Django Crispy Form中,我如何使用'layout.append(HTML( "<p>whatever</p>" ))'



我在阅读文档中阅读了关于脆皮表单的教程。我发现一些东西非常有用,在操纵布局在https://django-crispy-forms.readthedocs.org/en/d-0/dynamic_layouts.html

layout.append(HTML("<p>whatever</p>"))
layout.insert(1, HTML("<p>whatever</p>"))

so I try:

class PostJobForm(forms.ModelForm):    
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.layout.insert(1,  HTML("<p>Drag and drop photos and video here</p><p class='big'>+</p><p>Or click to add using the file browser</p>"),)
        super(PostJobForm, self).__init__(*args, **kwargs)
    class Meta:
        model=Job
        exclude=['employer','hitcount','location']

I got error

'NoneType' object has no attribute 'insert'

这个布局对象在哪里?教程中没有提到。

如何使用layout.insert(1, HTML("<p>whatever</p>"))

super(PostJobForm, self).__init__(*args, **kwargs)必须放在init对象下面。并在FormHelper()函数中添加self。

class PostJobForm(forms.ModelForm):    
    def __init__(self, *args, **kwargs):
        super(PostJobForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_tag = False

最新更新