0

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

tcarlander
  • 102
  • 8
  • possible duplicate of [Capturing url parameters in request.GET](http://stackoverflow.com/questions/150505/capturing-url-parameters-in-request-get) – Hedde van der Heide Mar 04 '13 at 12:16
  • Not a duplication, (i think) as the emphasis is different, the question asked in the other question is just how to get the parameters. I wanted to grab them directly in the urlpatterns. – tcarlander Mar 09 '13 at 17:58

1 Answers1

1

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':
        #...
Aidan Ewen
  • 13,049
  • 8
  • 63
  • 88
  • Thanks for the confirmation, I hoped it wold be possible, but did not think so. I will do it in ModRewrite to get cleaner code. – tcarlander Mar 09 '13 at 17:54