Templates in different directory
I want to place the project hierarchy in this way
project
|-app
| \app1
| |-templates
| \app1_templ.html
| |- views.py
| \-models.py
|-templates
| \main.html
|-views.py
|-models.py
...
But in the main.html i want to use `{%include app1_templ.html%}. Assuming the views.py from the app1:
def main(request):
info= Informations.objects.all()
return render_to_response('main.html', {'a':info})
and the app1_templ.html
{% for b in a %}
<li> title:{{ b.title }}</li>
{%empty %}
EMPTY
{% endfor %}
I have put in settings.py the TEMPLATE_DIRS an extra folder info
os.path.join(os.path.dirname(__file__), 'apps/app1/app1_templ').replace('\\','/'),
Rend开发者_如何学运维ering the page always seems to give EMPTY no matter what.
Why the a list seems to be empty?
Try passing in the context_instance
:
return render_to_response('main.html', {'a': info}, context_instance=RequestContext(request))
精彩评论