Reputation: 8296
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:
Upvotes: 2
Views: 378
Reputation: 6270
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_LOADERS
settings variableTEMPLATE_LOADERS
managed to load the template TemplateDoesNotExist
exception is raisedBy default TEMPLATE_LOADERS
is set to
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
)
As Matthew stated TEMPLATE_DIRS
is used solely by filesystem.load_template_source
loader. 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.html
urlpatterns = patterns('',
(r'^$', direct_to_template, {'template': 'authentication/index.html'}),
)
Unless you do so you cannot be sure that Django loads index.html from the authentication application.
Consider the behavior of app_directories.load_template_source
template 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:
Upvotes: 2
Reputation: 4403
Django will NOT automatically look for a templates directory, but there is a template loader (that comes by default) in settings.py called django.template.loaders.app_directories.Loader that will. I reccomend NOT using this because it does not namespace your templates. This means that a template called index.html under an appone/templates will hide a template called index.html under apptwo/templates (if apptwo is below appone in INSTALLED_APPS.
Upvotes: 1
Reputation: 6865
Yes, Django will search in other place's, but you NEED a template directory under your project.
Upvotes: 0