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

2
  • possible duplicate of Capturing url parameters in request.GET Commented Mar 4, 2013 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
    Commented Mar 9, 2013 at 17:58

1 Answer 1

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':
        #...
1
  • 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
    Commented Mar 9, 2013 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.