Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

python - why is logged_out.html not overriding in django registration?

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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...