I am currently working my way through the Django Tutorial (Step 3) and am stuck at the part with “Decoupling the URLconfs”.
What I try to do is to set up one URL-Pattern that catches lnadmin/, to redirect to the django admin, and eventually another catch-all that redirects to other patterns included from another file.
Here’s my mysite/urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^lnadmin/', include(admin.site.urls)), #match admin
url(r'^test/', include('lnapp.urls')), #match test, should be a catch-all later
)
and here’s the lnapp/urls.py, which is supposed to match hash/(anything)/:
from django.conf.urls import patterns, include, url
urlpatterns = patterns('lnapp.views',
url(r'^hash/(?P<hash>.+)/$', 'hash'), #match part to load from hash
)
I had this pattern in the main url.py before, and it worked as intended.
What’s happening now is that when I open (mydomain)/lnadmin/, it tries to access lnapp.views.hash (Could not import lnapp.views.hash, as no view is defined yet).
This doesn’t make any sense to me, as lnadmin/ should be matched by the first pattern, and /lnadmin/ doesn’t match test/hash/(anything)/. As soon as I comment out the one url in lnapp/urls.py, it redirects to the admin, as intended.
Swapping both urls in the main url.py has no effect.
The answer to my own question is: you have to define a view even for the unmatched urls, or else it will fail.