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 6122861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:56:56+00:00 2026-05-23T15:56:56+00:00

How i can match on the ?next=/nextpage/ value when i decorate a view in

  • 0

How i can match on the ?next=/nextpage/ value when i decorate a view in django with @login_required?
It’s not working on the “standard way” (in url.py via regular expression matching)!
Why it is not working on the standard way?

in urls.py:

(r'^login/$', 'foo.nb.views.signup'),
#(r'^login/?next=(?P<next>\S{1,250})$', 'foo.nb.views.signup'),

in views.py:

@login_required
def userpage(request):
    return HttpResponse('logged in -> ON USERPAGE')

again views.py:

#def signup(request, next=""): # the login
 def signup(request): # the login
    """ Logs a user in """
    if request.method=="POST" and request.POST['username'] and request.POST['password']:
            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)
                    #return redirect(next) # to sucess page
                     return redirect(request.GET['next']) # to sucess page
                else:
                    pass
                    # Return to disabled account error message
            else:
                # return invalid login error message
                pass
    return render_to_response('NBlogin.html')

when i visit views.userpage i will be redirected to my login page as expectet, and the url have the next field passed like /login/?next=/oldpage/, when i login with a correct user i receive an error message which told me that no next variable is passed (user, password is set) as get neither as post, (but the login works fine, as expected)

edit: Django 1.2: login issue (GET parameter: next) have the same topic, but i dont see a solution…

edit2: after changing to request.GET[‘next’] the error message says:

Key 'next' not found in <QueryDict: {}>

edit3:

I had to change the view like so:

def signup(request): # the login
    """ Logs a user in """

    if request.method=="GET":
            try:   
                    next = request.GET['next']
            except:
                    return render_to_response('NBlogin.html')
            return render_to_response('NBlogin.html',{'next' : next})

    if request.method=="POST" and request.POST['username'] and request.POST['password']:
            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)
                    return redirect(request.POST['next']) # to sucess page
                else:
                    pass
                    # Return to disabled account error message
            else:
                # return invalid login error message
                pass

    return render_to_response('NBlogin.html')

and i had to add a hidden field in my template, thats it!:

<form action="/login/" method="post">
        <p>Username:<input type="text" name="username"></p>
        <p>Password:<input type="password" name="password">
        <input type="hidden" name="next" value="{{next}}">
        <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-23T15:56:56+00:00Added an answer on May 23, 2026 at 3:56 pm

    Django only matches paths based on the path of the URL, not the querystring.

    This means that anything after ‘?’ in your request from the server is not considered when deciding which view to serve up. Instead, that part of the string is turned into a dictionary like object.

    so if you request:

    /login/?next=/nextpage/
    

    Django will use /login/ to find the view, and will populate request.GET with data {'next':'nextpage'}. Tell us what you’re actually trying to do and I’ll try to find a more Django-esque way for your to accomplish it.

    Edit after additional information supplied:

    The querystring ?next=/nextpage/ is probably not being sent when you submit the form with the POST method. Submitting the form will POST data to the URL specified in the form’s action attribute.

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

Sidebar

Related Questions

I don't know why i can't match url when url is http://localhost:8000/home/CPM%201.6.1001 since i
Can I match a value entered in textfield with two column in the database.
I know i can match numbers with Pattern.compile(\\d*); But it doesn't handle the long
How can I build a regular expression in python which can match all the
How can I match a field in the MySql-Database with a regular expression that
How can I match two lists of letters without considering the order of letters
How can I match the whole word in mysql? For instance, if I type
How can I match the following array with Rspec ? [#<struct Competitor html_url=https://github.com/assaf/vanity, description=Experiment
How can you match the following words by PHP, either by regex/globbing/...? Examples INNO,
How can I match a pattern in regex that can contain anything (letters,numbers,...) but

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.