3

Using resolve on a url without query params result in

resolve('/tracking/url/')
ResolverMatch(func=<function tracking_url_url at 0x028D62B0>, args=(), kwargs={}, url_name='tracking-url-url', app_name='None', namespace='')

Using resolve on a url with query params (the url works in the browser) results in an Resolver404 error

resolve('/tracking/url/?url=home')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 476, in resolve
    return get_resolver(urlconf).resolve(path)
  File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 352, in resolve
    raise Resolver404({'tried': tried, 'path': new_path})

The URL entry is

url(r'^tracking/url/$', 'myauth.views.tracking_url_url', name='tracking-url-url'),

What is the best way to resolve a url with query params and get a dict of the qs the same way i'm getting it from a regular request, e.g, request.GET.get('url').

Thanks.

haki
  • 9,389
  • 15
  • 62
  • 110

1 Answers1

3

resolve() and reverse() do not work on query parameters.

What you can do is: Resolve URL and then append your query parameter

"%s?url=home", resolve('/tracking/url/') (see this answer)

If you want to use request.GET.get(...), why don't you redirect to a view which uses request.GET.get(...)?

from django.shortcuts import redirect
from django.core.urlresolvers import resolve

def someViewFunction():
    ...
    url = "%s?url=home", resolve('/tracking/url/')
    return redirect(url)

If this does not help, try specifying your problem.

Community
  • 1
  • 1
Tommi Un
  • 173
  • 1
  • 9
  • 4
    There must be a function django uses to resolve url's into view_name & query parameters. Seems like i need to do some digging in the source. – haki Sep 22 '14 at 05:29