Warm tip: This article is reproduced from serverfault.com, please click

Django TemplateDoesNotExist Exception

发布于 2012-05-18 22:16:21

I was trying to use django-endless-pagination twitter pagination, but Django is throwing and exception and I'm having trouble debugging it.

After creating these templates:

search_results.html:

<h2>Entries:</h2>
{% include page_template %}

results.html:

{% for object in objects %}
    {# your code to show the entry #}
{% endfor %}

I added them to my projects template directory. I then create this view:

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')

When I go to the results url I get: Exception Type: TemplateDoesNotExist

Exception Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/loader.py in find_template, line 138

Template-loader postmortem

Django tried loading these templates, in this order: 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 (File exists) Using loader django.template.loaders.app_directories.Loader: /Users/some_account/Dropbox/code/project/project/course_database/templates (File exists) /Library/Python/2.7/site-packages/endless_pagination/templates (File exists) /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/auth/templates (File exists) /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/admin/templates (File exists) /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/admindocs/templates (File exists)

And the error during template loading is located at a line that includes: {% include page_template %}

Why would I be getting this exception, and how can I fix it?

Questioner
HighLife
Viewed
0
Furbeenator 2012-05-19 06:45:37

In your search_results.html page, you have {% include page_template %}, and I assume you are using locals() to pass it into the template. Can you output it on the template to verify what page_template's value is? Put {{ page_template }} in place of {% include page_template %} to verify it is getting the correct url.