provide ability to abort URL resolution early
|Reported by:||Chris Jerdonek||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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
urlpatterns = patterns('', url(r'^articles/', include(article_urls)), url(r'^articles/', page_not_found), url(r'^blogs/', include(blog_urls)), ... )
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.
Change History (5)
comment:1 Changed 2 years ago by
|Patch needs improvement:||unset|