私は次の見解を持っています:
from models import Table
from django.shortcuts import render_to_response, RequestContext
def myget(request,
template="project/p1.html",
page_template="project/p2.html"):
context = {
'objects': Table.objects.all(),
'page_template': page_template,
}
if request.is_ajax():
template = page_template
return render_to_response(template, context,
context_instance=RequestContext(request))
私のURLファイルは次のようになります:
url(r'^$', 'django.views.generic.simple.direct_to_template', {'template': 'master.html'}),
url(r'^p1', 'project.views.myget'),
次のように、master.html ファイルに p1.html (p2.html を含む) を含めています。
{% include "project/p1.html" with objects=objects %}
私は p1.html ファイルに p2.html を含めています:
{% include "project/p2.html" %}
master.html ファイルには p1.html が表示されますが、p2.html には表示されません (p1.html を単独でロードすると、p2.html が表示されます)。私は何が欠けていますか?「objects=objects」以外の変数をロードする必要がありますか?
編集: p1.html:
<!DOCTYPE HTML>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/style/endless.js" charset="utf-8"></script>
<script type="text/javascript" src="/style/endless_on_scroll.js" charset="utf-8"></script>
</head>
<body>
{% include "project/p2.html" %}
</body>
</html>
p2.html:
{% load endless %}
<table>
{% paginate 100,100 objects %}
{% for object in objects %}
<tr>
<td>{{ object.name }}</td>
</tr>
{% endfor %}
</table>
{% show_more %}