Question

I read the tutorial about crispy form in read the docs. I found some thing very useful, in Manipulating a layout in 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 tried:

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'

Where is this layout object? It doesn't mentioned in the tutorial.

How can i use the layout.insert(1, HTML("<p>whatever</p>"))

Was it helpful?

Solution

super(PostJobForm, self).__init__(*args, **kwargs) must place below init object. and add self to function FormHelper().

class PostJobForm(forms.ModelForm):    
    def __init__(self, *args, **kwargs):
        super(PostJobForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_tag = False
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top