Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 226
Bufke Avatar asked Jul 21 '11 16:07

Bufke


People also ask

How do I restrict access to admin pages in Django?

Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .

Should you use Django admin?

No. The django admin is not intended for any end-user. The django admin feature is intended to assist the website developer, and that is all.


1 Answers

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.

like image 91
Isaac Avatar answered Oct 11 '22 22:10

Isaac