Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting to another page after django admin login

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/.

like image 358
aemdy Avatar asked Jun 14 '12 15:06

aemdy


People also ask

How do I redirect one page to another in Django?

Django Redirects: A Super Simple Example Just call redirect() with a URL in your view. It will return a HttpResponseRedirect class, which you then return from your view. Assuming this is the main urls.py of your Django project, the URL /redirect/ now redirects to /redirect-success/ .

What we can do in admin portal in Django?

The Django admin application can use your models to automatically build a site area that you can use to create, view, update, and delete records. This can save you a lot of time during development, making it very easy to test your models and get a feel for whether you have the right data.

How do I redirect a user to login?

You can use session variable to do this, you ust be set session on login. So on edit page starting you can write following code to check wheter user is logged in or not.. your condition is bad, a simple issset($_SESSION) is not enough. another session might be set somewhere else.


1 Answers

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

like image 170
Funksen Avatar answered Oct 09 '22 17:10

Funksen