I'm trying to simply give an app url an option of /headless/
to make it show a different template.
My project/urls.py
has:
urlpatterns = [
url(r'^datastore/', include('datastore.urls')),
]
My app/urls.py
has:
app_name = 'datastore'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^datastore/(?P<headless>"headless"{1})/$', views.index,name='index'),
]
I'm getting a 404 error with the above.
I've also tried:
url(r'^datastore/(?P<headless>"headless"?)/$',
url(r'^datastore/(?P<headless>\w{1})/$', views.index, name='index'),
url(r'^datastore/(?P<headless>\w+)/$', views.index, name='index'),
You have to remove the prefix
/datastore/
from the appurlpattern
:According to Django's documentation:
So, the url pattern in your project's settings consumes the
datastore/
prefix. You should be able to check that this is so by trying/datastore/datastore/headless/
(this should work with your current configuration).Notice, however, that the combination of regular expression matches either
/datastore/headless/
or/datastore//
(the same in all your variations). This may not be what you want. Wilfried's answer (which does not address the real issue here) shows you how to better do what I think you intend to.