如何使用crispy表单助手来控制表单元素的布局,对于内置表单,如THIS帖子中提到的那样?
答案 0 :(得分:0)
我认为它已经很晚了,但我希望它可以帮到你:
<强> forms.py 强>
class PasswordResetFormExtra(auth.forms.PasswordResetForm):
def __init__(self, *args, **kw):
super(PasswordResetFormExtra, self).__init__(*args, **kw)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-lg-2'
self.helper.field_class = 'col-lg-8'
self.helper.layout = Layout(
'email',
Div(
Submit('submit', 'Reset password', css_class='btn btn-default'),
HTML('<a class="btn btn-default" href="/">Cancel</a>'),
css_class='text-left',
)
)
urls.py
from django.contrib.auth.views import password_reset
from .forms import(
PasswordResetFormExtra,
)
urlpatterns = patterns('',
(r'^/accounts/password/reset/$', password_reset, {
'template_name': 'my_templates/password_reset.html',
'password_reset_form':PasswordResetFormExtra,
}),
)
<强> password_reset.html 强>
{% load crispy_forms_tags %}
{% block content %}
{% crispy form %}
{% endblock %}