1

ドキュメントを読んで、クリスピーフォームに関するチュートリアルを読みました。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>"))

だから私は試しました:

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

エラーが発生しました

'NoneType' object has no attribute 'insert'

このレイアウトオブジェクトはどこにありますか? チュートリアルでは言及されていません。

どうすれば使えますかlayout.insert(1, HTML("<p>whatever</p>"))

4

1 に答える 1

1

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
于 2013-06-05T04:18:02.590 に答える