Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialpawkan kenluecha
26,303 Pointsasking about Url pattern order.
Today, I did this exercise. And I found something that I don't understand.
This was the working patterns.
urlpatterns = [
url(r'writer/(?P<pk>\d+)/$', views.writer_detail),
url(r'article/(?P<pk>\d+)/$', views.article_detail),
url(r'', views.article_list),
]
I tried something like this and it didn't work.
urlpatterns = [
url(r'writer/(?P<pk>\d+)/$', views.writer_detail),
url(r'', views.article_list),
url(r'article/(?P<pk>\d+)/$', views.article_detail),
]
Could someone explains me more detail about this ?
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsAs you may have learned, the first url pattern that matches the regex will be used. In your second example, the empty string r''
will match anything empty or not. To truly match the empty string, use anchor markers to indicate the entire string must be empty: r'^$'