0
如何使用crispy form helper來控制表單元素的佈局,例如THIS post中提到的內置表單的佈局?Crispy Forms和Django Password Reset表單
如何使用crispy form helper來控制表單元素的佈局,例如THIS post中提到的內置表單的佈局?Crispy Forms和Django Password Reset表單
我認爲它晚,但我希望它可以幫助你:
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 %}