Reputation: 6360
I am including templateInclude.html in templateA.html. While I can access {{ request.get_full_path }} from templateA.html, I cannot do so from templateInclude.html.
I would both like to solve and understand that problem. Is there a way of passing the request object to the included template?
Upvotes: 2
Views: 1830
Reputation: 6476
If you are using Django version 1.3+, then you can use:
{% include "templateInclude.html" with full_path=request.get_full_path %}
For earlier versions, you should use with
templatetag ie.
{% with request.get_full_path as full_path %}
{% include "templateInclude.html" %}
{% endwith %}
In the both cases, just use full_path
in the template which you will be including.
In general it works like context managers in regular python code - http://www.python.org/dev/peps/pep-0343/
Anyway it's weird because according to the docs, included templates have access to the whole context of parent template. Check if you're using RequestContext
in the view, or as a middleware.
Upvotes: 5