Redirect to the same page from where login is requested in django-website


I am trying to authenticate before some pages can be accessed and i want the page to be redirected to the same previous page from where login was called. How can we do that?

asked 2 years ago
Reputation: 1

1 Answer


To redirect to the same page from where login was called or required, each page with login link is required to know the current path and for that we need to add the request context preprocessor to In most cases it should already be present but if it’s not there then make sure it’s added properly.

It should look something like the code below in

            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [ ],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [



Now make the login link like this.

<a href="{% url 'account_login' %}?next={{request.path}}">Login</a>

In this account_login shows the relative url to the login page.

That’s it.

answered 2 years ago
Reputation: 1

Your Answer

Nothing to preview

Post Answer

Asked:  2 years ago
Viewed:  2720 times
Active:  2 years ago