tcarlander
tcarlander

Reputation: 102

Possible to use url parameters in URL pattern?

I am converting the serverside of a system from PHP to Django and am wodering if it is possible to have urlpatterns that depend on the parameters and not just the URL?

Example: These two urls executes two completely different functions:

/trackme/requests.php?a=upload

/trackme/requests.php?a=gettriplist

As I can not change the clients I would like to have them match two different patterns.

Currently I have to do a big if. I would like it to call directly the correct function from the URL

Thanks

Upvotes: 0

Views: 151

Answers (1)

Aidan Ewen
Aidan Ewen

Reputation: 13308

You can't, I'm afraid. The query string is stripped from the URL before any of the regex in your urlconf is matched.

I think your going to have to process the string in your view.

if 'a' in request.GET:
    if request.GET['a'] == 'upload':
        #...
    elif request.GET['a'] == 'gettriplist':
        #...

Upvotes: 1

Related Questions