Redirecting to another page after django admin login
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
If class based views is used check out the method_decorator
since I stumbled across the same problem, I noticed the url of the the default login page:
so I changed the login page link to
to point to the main page
works for the logout page too, nice and simple
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.
LOGIN_REDIRECT_URL in your
settings.py file. Documented here.
aemdy over 1 year
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/.
mlwn over 7 years@Daniel Backman , I know this is old, but how would you use this method when you are using class-based views, please ??
Daniel Backman about 7 years@mlwn check this: docs.djangoproject.com/en/1.10/topics/class-based-views/intro/…
mlwn about 7 years@DanielBackman I solved the issue by using mixin... but your solution looks neater. Unfortunately, login page is redirecting me to localhost/accounts/login ... oops.. 404. I have already made changes to the admin template by using myadmin, copying the template to my project folder ... so, login should direct to localhost/myadmin/login instead.. any ideas please ?
mlwn about 7 yearsam sorry, I mean I didn't copy the template to my project, but by adding my own admin.py to main app in project and redirecting my homepage to it... I hope I explained well...
mlwn about 7 yearsSorry.. :) you're great ... solved... I only have to specify the arguments of login_required as login_required(redirect_field_name='next', login_url='the login url') .... lol ... thanks alot....
dark_prince about 2 yearshow to do this?