2

Following is from urls.py:

url(r'^\?view=(?P<vtype>instructor|course|room)$', 'index', name='index'),

i can verify that it works by simply calling django.core.urlresolvers.reverse in shell :

In [6]: reverse('index', args=["course"])
Out[6]: '/?view=course'

but when i try to access http://localhost:8000/?view=course i get 404.

What am i doing wrong here?

Thanks

Edit:

url('^search/\?user=(?P<userid>\d+)&type=topic', 'search_forum', name='my_topics'),

this is from a former project which works as expected. sigh...

2
  • Do you have anything that is supposed to answer for that URL? Commented May 15, 2011 at 20:49
  • yes, index() normally works without regex. but adding query string regex breaks the url dispatching. Commented May 15, 2011 at 20:52

2 Answers 2

5

Query string is not part of the URL. If you want to do it this way, you have to use url(r'^$', 'index', name='index') and then look it up in request.GET dictionary in the view.

The usual way, however, is to use url(r'(?P<vtype>instructor|course|room)/$', 'index', name='index'). The querystring approach is the usual workaround for not being able to direct requests according to the non-querystring URL part. Django does not have that limitation.

Sign up to request clarification or add additional context in comments.

Comments

-1

Your regex matches from the beginning (^) but I don't see anything to match the leading '/'. Could this be it?

1 Comment

unfortunately not.django url dispatcher resolves the part after the root /. yet i tried if that could be it but no luck :)

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.