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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:35:41+00:00 2026-06-10T12:35:41+00:00

I am trying to do some Django URL matching. i want a few urls

  • 0

I am trying to do some Django URL matching.

i want a few urls where i have http://mysite.com/base?sort=type1/, http://mysite.com/base?sort=type2/, etc.

I can’t figure out how to URL match these expressions: I’m very new to Django and never used Reg Ex before.

What I have for urls.py in my “base” application is:

url(r'^$','base.views.main, name='main'),

I can’t figure out what to put to match my urls with question marks.

I’m trying something like

url(r'^?sort=popular/$', 'base.views.main_popular', name='main_popular'),

Thanks for help!

  • 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-10T12:35:43+00:00Added an answer on June 10, 2026 at 12:35 pm

    ? won’t match an “?” inside the url , instead it has its own meaning which you can look it up here :
    Python Regular Expressions
    If you want to match the exact character of “?” inside your url , you have to somehow escape it ( cause it has a meaning in RegExs ) so you might wanna escape it by a “\” (a backslash )
    so you would write \?sort ….

    EDIT :
    Okay so with what you’ve said in comments , seems here’s your problem , main?sort=popular occurs on your url pattern when you are rendering the template for /main/ with the GET method dictionary argument of sort=popular, just write a function that distinguishes between GET and POST , in the GET part , have sth like sort_by = request.GET.get('sort','') and then sort accordingly with the value of sort_by variable, would be sth like :

    def main_handler(request):
         if request.method == "POST":
               whatever ... 
         if request.method == "GET" :
               sort_by = request.GET.get('sort','')
               if sort_by:
                     sort by what sort points to 
                     return "the sorted template"
         return render_to_response(the page and it's args)
    

    and let go of that ? inside the url pattern , that’s added when you request a page with a GET argument.

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

Sidebar

Related Questions

So now I am still at the Django tutorial part 3: http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03 Trying to
I'm new to Django, trying to process some forms. I have this form for
Hello I'm a newbie trying to use django to register some users, I have
I'm trying to figure out a way to serialize some Django model object to
I'm trying to use the Django ORM in some standalone screen scraping scripts. I
I'm trying to use fixtures in Django to provide some initial data to one
I'm trying to send email with some images attached in django. Code used is
I'm trying to start writing unit tests for django and I'm having some questions
I have been trying some programs in the C Language and come across to
I'm trying to implement some customize login through the custom methods in Django's models.

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.