为什么在 Django 注册中没有覆盖logged_out.html? [英] why is logged_out.html not overriding in django registration?

查看:37
本文介绍了为什么在 Django 注册中没有覆盖logged_out.html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用内置的 django 登录和注销.在我的 Project/urls.py 中,我为登录和注销添加了 url.

I am using built-in django login and logout. In my Project/urls.py i have added url's for both login and logout.

from django.conf.urls import include, url
from account import views
from django.contrib.auth import views as auth_views
from django.contrib import admin
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$',views.index,name='Index'),
    url(r'^accounts/login/$',auth_views.login,name='login'),
    url(r'^accounts/logout/$',auth_views.logout,name='logout'),
    url(r'^accounts/register/$',views.register,name='register'),
    url(r'^accounts/profile/$',views.profile,name='profile'),    
]

我的帐户应用程序文件夹中有模板文件夹.我有这样的目录结构

and i've templates folder inside my account app folder. i have directory structure like this

account
   -templates
      -registration
          -login.html
          -logged_out.html
          -register.html
      -rest_html_files
-rest files

我读过 django 文档,其中说 login() 默认模板是 registration/login.html,它在我的项目中工作正常,如果没有提供参数,则 logout() 默认模板是 registration/logged_out.html它注销按钮(它有一个 href={% url 'logout' %} )被点击它重定向到管理员注销页面而不是我的自定义注销页面.可能有什么问题??

i've read django docs which say that for login() default template is registration/login.html which is working fine in my project and logout() default template is registration/logged_out.html if no arguments is supplied but whenever it Logout button ( which has a href={% url 'logout' %} ) is clicked it redirects to the admin logout page rather than my custom logout page. what could possibly be wrong??

推荐答案

django.contrib.admin 应用程序也有一个 registration/logged_out.html 模板.

The django.contrib.admin app also has a registration/logged_out.html template.

要确保使用您的帐户"应用中的模板,请确保它高于INSTALLED_APPS 设置中的django.contrib.admin".

To ensure that the template from your 'account' app, is used, make sure it is above 'django.contrib.admin' in your INSTALLED_APPS setting.

INSTALLED_APPS = (
    'account',
    ...
    'django.contrib.admin',
    ...
)

应用模板加载器遍历 INSTALLED_APPS 中的应用,以及每个应用的模板目录,直到找到匹配项.因此,如果 admin 高于您的应用,那么 Django 将使用来自 admin 的模板,而不是来自您的应用.

The app template loader goes through the apps in INSTALLED_APPS, and each app's template directory until it finds a match. Therefore, if admin is above your app, then Django will use the template from the admin instead of from your app.

这篇关于为什么在 Django 注册中没有覆盖logged_out.html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆