为什么在django注册中log_out.html不会被覆盖? [英] why is logged_out.html not overriding in django registration?
问题描述
from django.conf.urls import include, url
从帐户导入视图
从django.contrib.auth导入视图作为auth_views
从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'),
]
我在我的帐户应用程序文件夹中有模板文件夹。我有这样的目录结构
帐户
-templates
-registration
-login。 html
-logged_out.html
-register.html
-rest_html_files
-rest文件
我已经阅读了django文档,说login()默认模板是注册/ login.html这在我的项目和logout()中正常工作默认模板是注册/ logged_out.html如果没有提供任何参数,但是只要点击注销按钮(其中有一个href = {%url'logout'%}),它将重定向到管理注销页面,而不是我的自定义注销页面。
什么可能是错的?
django.contrib.admin
app也有一个
registration / logged_out.html
模板。
要确保使用帐户应用的模板,请确保它 django.contrib.admin您的 INSTALLED_APPS
设置。
INSTALLED_APPS =(
' ',
...
'django.contrib.admin',
...
)
应用程序模板加载程序会在 INSTALLED_APPS
和每个应用程序的模板目录中查看应用程序,直到找到匹配项。因此,如果管理员位于您的应用程式之上,那么Django将使用管理员的模板,而不是您的应用程式。
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
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??
The django.contrib.admin
app also has a registration/logged_out.html
template.
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',
...
)
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注册中log_out.html不会被覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!