我怎么不能使用Django的管理登录视图? [英] How can I not use Django's admin login view?

查看:127
本文介绍了我怎么不能使用Django的管理登录视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了自己的登录视图。但是,如果用户直接访问/ 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屋!

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