我是 Django 的新手,我正在尝试用酥脆的表单来设计表单。我的应用程序中有一个表单,它恰好是一个模型表单,我已经按照这里所说的https://stackoverflow.com/a/13201588/1076075使 ModelForm 与crispy_forms 一起工作,但收到此错误:
'FormHelper' object has no attribute 'append'
这就是我的代码的外观forms.py
:
from django import forms
from models import Ticket, Ticketuser
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Fieldset, ButtonHolder
from crispy_forms.bootstrap import FormActions
class AddTicketForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(AddTicketForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.append(Submit('save', 'save'))
class Meta:
model = Ticket
fields = ('id', 'comment')
def process(self):
data = self.cleaned_data
data = data['comment']
return data
如何克服这一点并按照我想要的方式设置表单样式?