Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the login_required redirect url in django?

I have a view function:

@login_required def myview():     # do something     # respond something     pass 

How can I specify the exact URL for this view function to be redirected?

like image 442
Pol Avatar asked Aug 26 '10 19:08

Pol


People also ask

Why is Django redirecting me to the login page?

When you are not logged-in and request a URL that requires authentication, like the Django admin, Django redirects you to the login page. When you log in successfully, Django redirects you to the URL you requested originally.

What is an unvalidated redirect in Django?

This kind of redirect is called an open or unvalidated redirect. There are legitimate use cases for redirecting to URL that is read from user input. A prime example is Django’s login view. It accepts a URL parameter next that contains the URL of the page the user is redirected to after login.

How to access Django admin without authentication?

Let’s see how. When you try to access a page of Django admin without authentication, it redirects you to the log-in page. There when you input the right credentials, it redirects you to the same page you wanted to access before the log-in page.

How to log out a user in Django using URL pattern?

They do not need to send any information, so to log out they should just go to the right URL. In urlpatterns you can find that for logout we use LogoutView class from django.contrib.auth.views module. Just import it to the urls.py module to complete the work.


1 Answers

LOGIN_URL in your settings

Reference:

  • LOGIN_URL
  • LOGIN_REDIRECT_URL
like image 193
Bob Avatar answered Sep 21 '22 21:09

Bob