? 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.