【问题标题】:Django-Registration Password Reset pulling in Admin TemplatesDjango-Registration Password Reset 拉入管理模板
【发布时间】:2014-02-28 20:27:28
【问题描述】:

我正在使用 Django 1.6 和 django-registration 1.0

我必须明确指定重置 URL

url(r'^password/reset/done/$', password_reset_done, name='password_reset_done'),

但它不断拉入管理模板。

为什么会这样? 如何将其覆盖为自定义模板?

更新: 尝试了以下,它仍然拉入管理模板...

url(r'^password/reset/', password_reset,
        {'template_name': 'registration/password_reset_form.html'}, name='password_reset'),
url(r'^accounts/password/reset/done/$', password_reset_done,
        {'template_name': 'registration/password_reset_done.html'}, name='password_reset_done'),

【问题讨论】:

    标签: python django django-templates django-registration


    【解决方案1】:

    我相信password_reset_done 是 django 内置应用程序之一的一种方法。您可以在 the official doc here.

    上阅读有关此身份验证应用程序的更多信息

    Django's url dispatcher allows to pass extra options to a view function.Luckily,password_reset_done 函数接受可选参数,如template_name,current_app 或extra_context。

    将这些放在一起,您可以执行以下操作:

    url(r'^password/reset/done/$', password_reset_done, {'template_name': PATH_TO_YOUR_CUSTOM_TEMPLATE}, name='password_reset_done'),
    

    要了解更多关于url函数的信息,请阅读this API doc。

    【讨论】:

      【解决方案2】:

      INSTALLED_APPS(在 settings.py 中)中应用程序列表的顺序是 Django 用于查找模板的顺序。如果两个模板共享相同的名称,那么首先列出的应用程序将获胜。这意味着在 INSTALLED_APPS 中,您需要确保“django.contrib.admin”应用程序位于包含您希望使用的模板文件的应用程序之后(大概是“注册”应用程序)。像这样:

      # settings.py
      ...
      INSTALLED_APPS = (
          ...
          'registration', # Or whichever app contains the template you want to use
          'django.contrib.admin',
          ...
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-18
        • 2014-02-15
        • 1970-01-01
        • 2023-03-23
        • 2011-03-12
        • 2021-10-27
        • 2019-08-26
        • 2023-04-03
        相关资源
        最近更新 更多