I have index.html, which loads project/p1.html, which loads project/p2.html. project/p1.html and project/p2.html each load fine on their own, so I know they work correctly. The problem is trying to load project/p1.html into index.html, which has the statement:
{% include 'project/p1.html' %}
project/p1.html has the statement:
{% include 'project/p2.html' %}
Loading index.html, I get the error:
VariableDoesNotExist at /
Failed lookup for key [objects] in u"[{'params': {}}, {'csrf_token': <django.utils.functional.__proxy__ object at 0x7fd3dc0e2410>}, {'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x7fd3dc0e2210>, 'user': <django.utils.functional.SimpleLazyObject object at 0x7fd3dc10c790>}, {},......
If I delete “{% include ‘project/p2.html’ %}” from project/p1.html, index.html loads fine and the error message dissapears (but obviously I can’t see my content).
How do I resolve this?
EDIT: Heres “project/p2.html”:
<table class="mytable">
{% for object in objects %}
<tr class="my_row">
<td>{{ object.name }}</td>
</tr>
{% endfor %}
</table>
Here’s views.py:
from models import Mytable
from django.shortcuts import render_to_response, RequestContext
def my_request(request,
template="project/p1.html",
page_template="project/p2.html"):
context = {
'objects': Mytable.objects.all().order_by('-date'),
'page_template': page_template,
}
if request.is_ajax():
template = page_template
return render_to_response(template, context,
context_instance=RequestContext(request))
It’s looking for variables that aren’t available to it. Pass in additional context parameters.
{% include "name_snippet.html" with person="Jane" greeting="Hello" %}EDIT: Documentation.