I am making a custom administration page in Django. I do not want to reinvent the wheel and thus want to use Django admin login form for the staff to log in and redirect them to /my-url/ afterwards.
However, I can't find the way to redirect user to a custom url after successful login at /admin/.
I had the same issue.
Instead of redirect after login I used the @staff_member_required decorator
for my view /my-url/
which redirects to the admin login
from django.contrib.admin.views.decorators import staff_member_required
@staff_member_required
def test_list(request):
return HttpResponse('TEST')
If class based views is used check out the method_decorator
The Django auth app comes with a login view which you can hook up to /accounts/login/
or any other url you choose. You can probably use the admin's login template admin/login.html
if you don't want to write your own.
By using the login view, the LOGIN_REDIRECT_URL
parameter will work. The purpose of the /admin/
page is to display the admin index. I would avoid trying to use it as the login page.
Set LOGIN_REDIRECT_URL
in your settings.py
file. Documented here.
since I stumbled across the same problem, I noticed the url of the the default login page:
/admin/login/?next=/admin/
so I changed the login page link to
/admin/login/?next=/
to point to the main page
works for the logout page too, nice and simple