Reputation: 35682
This is the structure of my site:
mysite
app_a
templates
a.html
app_b
templates
b.html
views.py
In views.py
, I want to get a.html
,
So I use this :
return render_to_response('app_a/a.html')
but it shows an error :
TemplateDoesNotExist
What do I need to do?
Upvotes: 4
Views: 2715
Reputation: 118488
just use render_to_response('a.html')
Assuming you have the default app directory template loaders on, the problem is that the template path is actually a.html
So in your current format, you would write a.html
not app_a/a.html
The recommended format for template directories is
mysite
app_a
templates
app_a
a.html
app_b
templates
app_b
b.html
views.py
global_templates
app_b
b.html
which would work with your example of app_a/a.html
The reason this format is recommended is so you can sanely override templates on a per-app basis.
You can easily get conflicting template names if all files are directly in the app template directory.
Upvotes: 6
Reputation: 91
Besides the TEMPLATE_DIRS
settings, try adding django.template.loaders.app_directories.Loader
to the TEMPLATE_LOADERS
setting as this will make available all the templates for the apps in your INSTALLED_APPS
. That way you don't need to put them all under one master directory.
See the Django Documentation for template loaders
Upvotes: 1
Reputation: 862
You can specify a TEMPLATE_DIRS variable in settings.py, which is a tuple of directories where templates are searched for. If you add the template directory from both apps to TEMPLATE_DIRS, you should be okay (just watch out for conflicts in the search path).
Upvotes: 1