【问题标题】:Crispy Forms and Django Password Reset FormCrispy 表单和 Django 密码重置表单
【发布时间】:2014-05-31 14:32:47
【问题描述】:

THIS帖子中提到的内置表单,我如何使用crispy form helper来控制表单元素的布局?

【问题讨论】:

    标签: django django-crispy-forms


    【解决方案1】:

    我觉得有点晚了,但希望对你有帮助:

    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 %}
    

    【讨论】:

      猜你喜欢
      • 2012-07-18
      • 2020-08-04
      • 2015-12-12
      • 2012-04-16
      • 2019-01-08
      • 2021-01-05
      • 1970-01-01
      • 2017-07-08
      • 2019-07-19
      相关资源
      最近更新 更多