【发布时间】:2016-02-28 23:32:13
【问题描述】:
我一直致力于使用 django-crispy-forms、Django 1.8.4 和 django-crispy-forms-1.5.2 创建模型表单。我无法更改表单标签属性。
我已经尝试设置self.helper.form_tag = False,但它仍然会产生<form> 标记。我试过设置其他属性,比如form_action,但这也不起作用,表单标签保持不变(最终的HTML仍然只是<form>)。
在views.py:
class RegisterStudentView(CreateView):
template_name = "register_student.html"
model = Student
form_class = StudentRegistrationForm
def form_valid(self, form):
form.save()
return HttpResponseRedirect('dashboard')
在forms.py:
class StudentRegistrationForm(ModelForm):
def __init__(self, *args, **kwargs):
super(StudentRegistrationForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
class Meta:
model = Student
exclude = ['is_active', 'is_overdue', 'personid', 'tertiary_cell']
任何帮助将不胜感激。
【问题讨论】:
-
您的 html 模板中有什么?表单标签可能在那里而不是由crispy-forms生成的
-
谢谢@awwester,这正是我的问题。我对脆皮表格的调用周围有一个表格标签。
标签: python django forms django-crispy-forms