我有以下看法:
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(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 %}