Opened 11 years ago
Closed 11 years ago
#22781 closed Cleanup/optimization (wontfix)
Improve named regular-expression groups example to capture URL bits
| Reported by: | Pablo Oubiña | Owned by: | nobody |
|---|---|---|---|
| Component: | Documentation | Version: | 1.6 |
| Severity: | Normal | Keywords: | url, regular, expression, regex, group |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Hi folks!
Documentation shows https://docs.djangoproject.com/en/dev/topics/http/urls/#named-groups:
from django.conf.urls import url
urlpatterns = [
url(r'^articles/2003/$', 'news.views.special_case_2003'),
url(r'^articles/(?P<year>[0-9]{4})/$', 'news.views.year_archive'),
url(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', 'news.views.month_archive'),
url(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', 'news.views.article_detail'),
]
I think this would be more flexible:
from django.conf.urls import url
urlpatterns = [
url(r'^articles/2003/$', 'news.views.special_case_2003'),
url(r'^articles/(?P<year>[0-9]{4})/$', 'news.views.year_archive'),
url(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/$', 'news.views.month_archive'),
url(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/(?P<day>[0-9]{1,2})/$', 'news.views.article_detail'),
]
Change History (2)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
The format used in the example also has the advantage of being unambiguous. It's a bad practice to have multiple URLs pointing to the same page, and that would be possible with the lax format.
Note:
See TracTickets
for help on using tickets.
Well, I think the wide-spread standard on the web is to use a two-digit month, 01 through 12, and a two-digit day, 01 through 31 in URLs dates.