TIMEX
TIMEX

Reputation: 271904

How come this Django matching doesn't work in urls.py?

(r'^signup(.*)password=goodbye$','abc.wall.views.register_goodbye'),

This doesn't work. It doesn't match! Even when I hit this:

www.mydomain.com/signup?password=goodbye

It does not match it and simply skips over it. Why?

Note: I understand this is not good practice to match the GET parameter. However, it's forced and I must do it due to code that I can't change.

Upvotes: 1

Views: 142

Answers (2)

Josh Smeaton
Josh Smeaton

Reputation: 48730

URLs don't match on query parameters. They take the path (everything before the ?) from the request, and attempts to match against your URL regex.

What you need to do is handle the GET parameters in your view, and route from there to other functions if you need to. Example:

request: http://www.mydomain.com/signup/?password=goodbye 

(r'^signup/$','abc.wall.views.signup_front')

def signup_front(self, request):
    query_param = request.GET.get('password', None)
    if query_param == "goodbye":
        return signup_goodbye(request)
    # other stuff here

def signup_goodbye(self, request):
    # blah
    # return render_to_response(..)

Upvotes: 1

Related Questions