I started going through The Definitive Guide to Django and now would like to start working on my own project. I have Django set up and everything. I created a project called djangoproject1. Basically what I would like is that the main page is a registration/login page. My urls.py for djangoproject1 looks like this:
urlpatterns = patterns('',
(r'^/',include('djangoproject1.authentication.urls')),
)
I have a pydev package (application) under djangoproject1 called authentication which has an urls.py that looks like this:
urlpatterns = patterns('',
(r'^$',direct_to_template,{'template':'index.html'}),
)
A couple of questions:
- I’m getting a page not found error which means I’m probably doing my mapping/include incorrectly
- If I don’t specify anything under TEMPLATE_DIRS in settings.py, my understanding is that Django will look in each package for a directory named templates. Is that correct?
What Asinox has said is not true. You MAY have a global template directory, even several of them. But that is not a must.
In fact template loading is done as follows:
TEMPLATE_LOADERSsettings variableTEMPLATE_LOADERSmanaged to load the templateTemplateDoesNotExistexception is raisedBy default
TEMPLATE_LOADERSis set toAs Matthew stated
TEMPLATE_DIRSis used solely byfilesystem.load_template_sourceloader. So if you exclude it from the list it won’t have any impact on template loading process at all.In order for your template to be found I’d suggest you to do the following:
. `-- djangoproject1 `-- authentication `-- templates `-- authentication `-- index.htmlUnless you do so you cannot be sure that Django loads index.html from the authentication application.
Consider the behavior of
app_directories.load_template_sourcetemplate loader.Pretend you have just defined two applications app1 and app2 (no other apps are defined) and asked to load template ‘path/to/template.html’.
The loader will check the following paths in no particular order: