I’m using django.views.generic.list_detail.object_detail.
According to the documentation the view takes the variable object_id. To do this I added the following to my urlconf:
(r'^(?P<object_id>\d+)$', list_detail.object_detail, article_info),
The above line is in a separate urlconf that is included in the main urlconf.
If I leave the ‘^’ character at the beginning of the pattern and then attempt to go to the address:
…/?object_id=1
It does not work. If I remove the ‘^’ character the address:
…/?object_id=1
Still does not work. However if I use:
…/object_id=1 (without the question mark)
The view accepts the object_id variable and works without a problem. I have two questions about this.
First: Can the ‘^’ character in an included urlconf be used to restrict the pattern to only match the base url pattern plus the exact string bettween a ^$ in the included urlconf?
Second: Why does the question mark character stop the view from receiving the ‘object_id’ variable? I thought the ‘?’ was used to designate GET variables in a URL.
thanks
I’ll tackle your second question first. The
?character in this context is used to denote a named group in the regular expression. This is a custom extension to regular expressions provided by Python. (See the howto for examples)To pass an
object_idappend it to the URL (in your case). Like this:../foo/app/3where3is theobject_id.