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

  • SEARCH
  • Home
  • 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 4601420
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:49:20+00:00 2026-05-21T23:49:20+00:00

I am having troubles with the redirect to the same page user was on

  • 0

I am having troubles with the redirect to the same page user was on after logging in, no matter how hard I tried and read all the questions here. I think it is high time I showed folks out here my code so if you can point out mistake(s). Thanks.

My login url (in base.html template):
This is present on every page. Changes to logout once the user is logged in. I read that I have to pass a param for example ‘next’ like this:

 <a href="/login/?next={{request.path}}">Login</a>

but,

*The {{request.path}} is always empty. *

login view:

def mylogin(request):
    """login view"""
    try:
        redirect_to = request.GET.get('next', '/')
    except ValueError:
        redirect_to = "/"

errors = ''
t = loader.get_template('login.html')


# check for POST data
if request.method == 'POST':
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            # Redirect to a success page.
            return HttpResponseRedirect(redirect_to)
        else:
            c = Context({
                'errors':'disabled',
            })
            return HttpResponse("disabled")
    else:
        c = Context({
            'errors':'incorrect',
        })
        return HttpResponse(t.render(c))
else:
    c = Context({
        'errors':None,
    })
    return HttpResponse(t.render(c))

The login form, in login.html template

 <form method="post" action="?next={{ redirect_to }}" >
       <p><label for="username">Username</p>
       <p></label><input type="text" name="username" value="" id="username" /></p>
       <p><label for="password">Password</label></p>
       <p><input type="password" name="password" value="" id="password" /></p>
       <p><input type="submit" value="Login"></p>
 </form>
  • 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-05-21T23:49:21+00:00Added an answer on May 21, 2026 at 11:49 pm

    You’re not passing request to the template context, so naturally it’s empty. The easiest way to get it in there is to use a RequestContext, which uses the built-in context processors to add variables to the context.

    The usual way to do this is to use render_to_response with the extra parameter context_instance=RequestContext(request). For some reason, you’re rendering all your templates the long way, so you’ll need to create that requestcontext yourself.

    You’ll also need to add django.core.context_processors.request to the CONTEXT_PROCESSORS tuple ins settings.py.

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

Sidebar

Related Questions

I am having trouble trying to pass an valuable after the user fail the
i'm having troubles with the bhLDAPAuthPlugin for symfony when the user session expires. It
I am trying to redirect the user to edit details of a task after
I am having trouble figuring out how to 're-render' a page after a POST
I'm having troubles with HttpWebRequest/HttpWebResponse and cookies/CookieContainer/CookieCollection. The thing is, if the web server
I am having troubles migrating from OC4J 10.1.2.3 to 10.1.3.1.4. The problem is for
I'm having troubles with the order of my code in my program. right now
I'm having troubles using Blend with my visual studio solution. In Runtime, and compile
im currently having troubles on my codes in C#. I want to split strings
I am having troubles with jQuery's load function and am hoping for some help.

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.