Andy McKay

Jan 23, 2009

Grouping in Django URL's


I wanted to include a regular expression in my Django URL's, but I didn't want to that be passed as an argument to the view. The answer is in the Python regular expression documentation:

(?:...) A non-grouping version of regular parentheses

So in my case a URL like:

r'^(?:site/[0-9]+/)view/(?P<id>.*)/$

Would match the URL:

/site/1/view/2/

But by using (?: only the id is passed to the view.