Opened 20 months ago

Closed 20 months ago

Last modified 20 months ago

#29146 closed Bug (fixed)

re_path() examples are missing ^ and $ in regexes

Reported by: Seohong Park Owned by: nobody
Component: Documentation Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

An example about the usage of re_path() in 'URL dispatcher' document https://docs.djangoproject.com/en/2.0/topics/http/urls/ is misleading.

Since re_path() does not insert '$' at the end of URL parameter (on the contrast, path() inserts '^' and '$' at the beginning and the end of URL parameter),

re_path('articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/', views.month_archive) would not be mapped to any URL, because re_path('articles/(?P<year>[0-9]{4})/', views.year_archive) shades it.

(i.e. 'http://127.0.0.1:8000/articles/2018/12/' invokes views.year_archive, not views.month_archive)

This is misleading, because readers might think re_path also automatically inserts '^' and '$' to the parameter like path does.

I think it would be better to insert '$' at the end of each parameter of re_path() in the document.

Additionally, mentioning about the fact that path() automatically inserts '^' and '$' to the parameter also would be helpful.

Change History (4)

comment:1 Changed 20 months ago by Seohong Park

Has patch: set

comment:2 Changed 20 months ago by Tim Graham

Summary: An example in 'URL dispatcher' document is misleadingre_path() examples are missing ^ and $ in regexes
Triage Stage: UnreviewedReady for checkin

comment:3 Changed 20 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 9716860:

Fixed #29146 -- Readded and $ inadvertently removed from re_path() examples.

comment:4 Changed 20 months ago by Tim Graham <timograham@…>

In ea0dc5df:

[2.0.x] Fixed #29146 -- Readded and $ inadvertently removed from re_path() examples.

Backport of 97168605965143f02c27dac718b6b3e317a4be26 from master

Note: See TracTickets for help on using tickets.
Back to Top