代码之家  ›  专栏  ›  技术社区  ›  frnhr

django.contrib.auth视图和模板变量

  •  1
  • frnhr  · 技术社区  · 14 年前

    在我的“根”模板中,我有这样的东西

    {% if special %}
    some_special_html
    {% endif %}
    

    这个 special 模板变量由某些视图插入到模板中。

    问题是我需要 password_change 查看以全部设置 特殊的 模板变量。

    最好的办法是什么?

    目前 密码更改 视图直接从url.py调用:

    url(r'^change_password/$', 'django.contrib.auth.views.password_change',
        {'template_name': 'profile/password_change.html'},
        name='password_change'),
    
    2 回复  |  直到 14 年前
        1
  •  3
  •   Duncan Parkes jbochi    13 年前

    至少从Django 1.3开始 password_change

    通过使用 kwargs 的论点 url 函数,因此要获取额外的上下文,请执行以下操作:

    url(r'^password/change/$',
        auth_views.password_change,
        {'template_name': 'profile/password_change.html'},
        name='password_change',
        kwargs=dict(extra_context={'special': 'special'}),
        ),
    
        2
  •  0
  •   Sam Dolan    14 年前

    或者移动您对 special var到上下文处理器中,或者只将 password_change 使用在正确上下文中传递的自己的视图验证视图。