2👍
✅
You need to additionally check for the beginning of the string (^
):
url(r'^(?P<pagename>\w)/$', views.show_page, name='page'),
url(r'^(?P<pagename>\w)/info/$', views.show_info, name='info'),
Without it (?P<pagename>\w)/$
regex would catch both some-page-name/
and some-page-name/info/
urls, since it is checking for a single alphanumeric character, a slash and an end of the string:
>>> re.search(r'(?P<pagename>\w)/$', 'p/').group(1)
'p'
>>> re.search(r'(?P<pagename>\w)/$', 'p/info/').group(1)
'o'
Source:stackexchange.com