我是Django的新手,我正在尝试使用简洁的表单来样式化表单。我的应用程序中有一个恰好是模型表单的表单,我已经按照这里所说的https://stackoverflow.com/a/13201588/1076075使ModelForm与crisply_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
如何克服这个问题并按照我想要的方式设置表单样式?
绝地无双
相关分类