tickets: 22425
This data as json
id | created | changetime | last_pulled_from_trac | stage | status | component | type | severity | version | resolution | summary | description | owner | reporter | keywords | easy | has_patch | needs_better_patch | needs_tests | needs_docs | ui_ux |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
22425 | 2014-04-12 15:57:15 | 2021-06-29 15:19:38 | 2022-03-06 04:18:58.703687 | Accepted | assigned | Core (URLs) | New feature | Normal | dev | provide ability to abort URL resolution early | 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. | Tijani-Dia | cjerdonek | 0 | 0 | 0 | 0 | 0 | 0 |