我在阅读文档时阅读了关于crispy表单的教程。我在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>"))
答案 0 :(得分: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