id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux
22425 provide ability to abort URL resolution early Chris Jerdonek nobody "This is a feature request to provide a way to abort early from URL resolution if a regex doesn't match. I was able to figure out a way to do this myself using some wrapper constructs, but it seemed unnecessarily tricky and also relied on Django internals (and so may be brittle).
To illustrate the use case, consider a typical URLconf:
{{{
urlpatterns = patterns('',
url(r'^articles/', include(article_urls)),
url(r'^blogs/', include(blog_urls)),
...
)
}}}
While the above is common, it also seems common that one would want URL resolution to result in a 404 if an URL matches `^articles/` but does not match the first `url()` pattern above. This would be the case, for example, when all `article` URLs should be in the `article_urls` URLconf. However, Django would process such an URL by unnecessarily continuing to examine every pattern in `urlpatterns` that follows (`^blogs/`, etc). It would be good to have a way to achieve this 404 functionality in a performant and DRY way.
For example, the following would not be as performant or DRY as it could be because you have to duplicate the regex and because Django's URL resolver would unnecessarily need to match against `^articles/` twice:
{{{
urlpatterns = patterns('',
url(r'^articles/', include(article_urls)),
url(r'^articles/', page_not_found),
url(r'^blogs/', include(blog_urls)),
...
)
}}}
Modifying `account_urls` and `public_urls` etc by including `page_not_found` is also not a good solution because it is not DRY (the `page_not_found` addition needs to be repeated) and because those URLs might be in third-party libraries.
" New feature new Core (URLs) master Normal chris.jerdonek@… Accepted 0 0 0 0 0 0