Reputation: 33491
I have my urls.py
included like this:
urlpatterns = [
path('files/', include('files.urls')),
]
then, in files/urls.py
, I put this:
urlpatterns = [
path('', views.index, name='index'),
path(r'(?P<name>[a-z]+)', views.check, name='check')
]
So, I assume that when example.com/files
works, so should example.com/files/somename
, but it doesn't:
Using the URLconf defined in example.urls, Django tried these URL patterns, in this order:
[name='index'] files/ [name='index'] files/ (?P<name>[a-z]+) [name='check']
The current path, files/somename, didn't match any of these.
What am I missing here?
Upvotes: 0
Views: 1330
Reputation: 47354
You don't need to use regexp with path
method. Instead you can simply specify str
as argument type:
path('<str:name>/', views.check, name='check')
If you want to use regular expression, use re_path
:
re_path(r'(?P<name>[a-z]+)', views.check, name='check')
Upvotes: 3