Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7731273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:26:23+00:00 2026-06-01T06:26:23+00:00

In my template I am currently using the next parameter to redirect the user

  • 0

In my template I am currently using the next parameter to redirect the user back to the page before the login page with this:

<a href="{% url auth_login %}?next={% firstof request.path '/' %}">Log in</a>

The firstof tag makes sure that in case request.path is invalid, then it will redirect back to the root URL.

This works well on every page except one: the logout page. If I wanted to switch user, then I would first log out, then click log in. But then my url would be

http://127.0.0.1:8000/accounts/login/?next=/accounts/logout/

So as soon as I log in, I would immediately be logged back out again. How do I modify the template so with something like this pseudocode:

if request.path and request.path != reverse( 'auth_logout' )
    return request.path

return "/"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:26:24+00:00Added an answer on June 1, 2026 at 6:26 am

    The easiest solution I can think of, is add “?next=/” to your logout url, that way, as soon as the user logs out, he will be immediately redirected to the specified url, so no one will ever stay on logout page upon logout.

    Otherwise you would have to rewrite the login view and add any custom logic you need, which would be easier if contrib.auth views were class views, which they are currently not unfortunately.

    So copy paste it and modify 🙂 (I know that copy pasting is bad, but thats the only way you could add custom behavior to it).

    The view is located here:
    https://code.djangoproject.com/browser/django/trunk/django/contrib/auth/views.py#L25

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using this syntax in my Django 1.1.2 template: {% ifnotequal myvalue
Currently I am using xCode 3.2.5 and I have already installed cocos2d template cocos2d
So I have this template design that is currently absolutely positioned, but I'm trying
Currently, django.contrib.comments sends the user to the preview page if there is any error
I'm currently using macros to declare relatively long lists of partially specialized template classes
My first problem : I am currently using $(window).load to delay the page render
I'm currently using NVelocity to render some email templates. I'm curious how I can
I currently use C for numerical computations. I've heard that using C++ Expression Templates
Can firebug be used to show me which rails template is currently being viewed
I am currently writing a C++ template expression library and comparing some instantiations with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.