我怎么不能使用Django的管理登录视图? [英] How can I not use Django's admin login view?
问题描述
我创建了自己的登录视图。但是,如果用户直接访问/ admin,则将其带入管理员登录页面,并且不使用我的自定义视图。如何使其重定向到用于所有不是/ admin的登录视图?
I created my own view for login. However if a user goes directly to /admin it brings them to the admin login page and doesn't use my custom view. How can I make it redirect to the login view used for everything not /admin?
推荐答案
从 http://djangosnippets.org/snippets/2127/ - 使用 login_required
包装管理员登录页面。例如,在django.contrib中的 urls.py
中:
From http://djangosnippets.org/snippets/2127/—wrap the admin login page with login_required
. For example, in urls.py
:
from django.contrib.auth.decorators import login_required
from django.contrib import admin
admin.autodiscover()
admin.site.login = login_required(admin.site.login)
你可能已经有中间两行,甚至可能是第一行;添加第四行将导致任何将击中 admin.site.login
函数的东西重定向到您的 LOGIN_URL
与适当的下一个
参数。
You probably already have the middle two lines and maybe even the first line; adding that fourth line will cause anything that would have hit the admin.site.login
function to redirect to your LOGIN_URL
with the appropriate next
parameter.
这篇关于我怎么不能使用Django的管理登录视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!