How can I not use Django's admin login view?

后端 未结 10 2652
借酒劲吻你
借酒劲吻你 2020-12-28 15:11

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

10条回答
  •  抹茶落季
    2020-12-28 15:23

    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)
    

    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.

提交回复
热议问题