Reputation: 11929
Is there any way to debug why Django fails to find template file but to edit and debug the loader source code? The Debug configuration flag seems to do nothing.
This is only error I get, it would help I could find out what paths it tries to look into.
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/template/loader.py", line 131, in find_template
raise TemplateDoesNotExist(name)
django.template.base.TemplateDoesNotExist: mytemplate.xml
Upvotes: 2
Views: 201
Reputation: 197
In your project settings.py you have a TEMPLATE_DIRS dictionary, where you can add different paths where django will look into, searching for the matching template.
Take this for example:
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'templates'),
)
As you can see, here is an absolute path to my desired templates folder ( read os.path for os.path details; file from os.path.dirname() means the settings.py file folder, where is located )
In your view, you return a response, take this for example:
return render_to_response('index.html', context)
Django will look into the desired path, being /home/user/path_to_project/templates/ for a file located at '/index.html'. Basically, Django will look into templates/). If, for example, you would've typed 'homepage/index.html', Django would've looked in /home/user/path_to_project/templates/homepage/index.html.
One way to debug the template error, is to see what url you are trying to get, see the url's path view and check for your template path to see if it's correct in your view's returned response.
Hope that this clarifies a bit, if you need more information read: https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.render_to_response
Upvotes: 1