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?
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With