Can I use the login page available at: /admin
for non-staff users to login? I'm using the following settings in my django settings file:
LOGIN_URL = '/admin/'
LOGIN_REDIRECT_URL = '/'
When I login, it doesn't redirect me to the root folder. Am I doing it the right way?
Note: I'm using decorator @login_required
on my view.
Edit
It logs me in to admin site with this URL: http://127.0.0.1:8000/admin/?next=/
Non-staff members can't login through the admin view, so you can't.
There is a Django view that does exactly what you need, however:
django.contrib.auth.views.login
You can easily add it to your
urlconf
:Check the documentation to see how you can customize its behavior: https://docs.djangoproject.com/en/dev/topics/auth/#limiting-access-to-logged-in-users
You'll only need to define a template for the view to use, by default, it should be located at
registration/login.html
, but that can be overriden.UPDATE
1) For django 1.11+ better use LoginView (i.e.
from django.contrib.auth.views import LoginView
) sincelogin
code actually uses LoginView and the code oflogin
even has a warning messge:2) You may want to change the default header of admin's login page. That can be done by providing
site_header
in context.So updated version would look like this: