我试图使用 django-endless-pagination twitter pagination,但是 Django 正在抛出异常,我在调试它时遇到了麻烦。
创建这些模板后:
search_results.html:
<h2>Entries:</h2>
{% include page_template %}
结果.html:
{% for object in objects %}
{# your code to show the entry #}
{% endfor %}
我将它们添加到我的项目模板目录中。然后我创建这个视图:
def search(request):
if 'q' in request.GET: #Need to add input variable to html code
q = request.GET['q']
if q:
stuff = Stuff.objects.filter(name__icontains=q)
template = "search_results.html"
page_template = "results.html"
if request.is_ajax():
template = page_template
return render_to_response(template, locals())
return render_to_response('search_page.html')
当我转到结果网址时,我得到: 异常类型: TemplateDoesNotExist
异常位置: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/loader.py in find_template,第 138 行
模板加载器事后分析
Django 尝试按以下顺序加载这些模板: Using loader django.template.loaders.filesystem.Loader: /Users/some_account/Dropbox/code/project/project/html (File exists) /Users/some_account/Dropbox/code/project /project/course_database/templates(文件存在)使用加载程序 django.template.loaders.app_directories.Loader:/Users/some_account/Dropbox/code/project/project/course_database/templates(文件存在)/Library/Python/2.7/site -packages/endless_pagination/templates(文件存在)/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/auth/templates(文件存在)/Library/Frameworks/Python .framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/admin/templates(文件存在)/Library/Frameworks/Python.framework/Versions/2.7/lib/python2。7/site-packages/django/contrib/admindocs/templates(文件存在)
模板加载期间的错误位于包含以下内容的行:{% include page_template %}
为什么我会得到这个异常,我该如何解决?