Template Loader finds the template but template is not loaded
TemplateDoesNotExist at /cardpayment/
cardpayment.html
Request Method: GET
Request URL: http://localhost:7000/cardpayment/
Django Version: 1.8
Exception Type: TemplateDoesNotExist
Exception Value:
cardpayment.html
Exception Location: /home/sdr/sl/lib/python3.4/site-packages/django/template/loader.py in render_to_string, line 138
Python Executable: /home/sdr/sl/bin/python
Python Version: 3.4.3
Python Path:
['/home/sdr/sl/agryp',
'/home/sdr/pycharm-4.0.6/helpers/pydev',
'/home/sdr/sl/src/tastypie',
'/home/sdr/sl/agryp',
'/usr/local/lib/python34.zip',
'/usr/local/lib/python3.4',
'/usr/local/lib/python3.4/plat-linux',
'/usr/local/lib/python3.4/lib-dynload',
'/home/sdr/sl/lib/python3.4/site-packages']
Server time: Tue, 5 May 2015 10:17:40 +0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/home/sdr/sl/agryp/templates/cardpayment.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
/home/sdr/sl/agryp/agryp/templates/cardpayment.html (File exists) <=========== FILE EXISTS BUT NOT LOADED
/home/sdr/sl/src/tastypie/tastypie/templates/cardpayment.html (File does not exist)
/home/sdr/sl/lib/python3.4/site-packages/grappelli/templates/cardpayment.html (File does not exist)
/home/sdr/sl/lib/python3.4/site-packages/django/contrib/admin/templates/cardpayment.html (File does not exist)
/home/sdr/sl/lib/python3.4/site-packages/django/contrib/auth/templates/cardpayment.html (File does not exist)
/home/sdr/sl/lib/python3.4/site-packages/oauth2_provider/templates/cardpayment.html (File does not exist)
/home/sdr/sl/lib/python3.4/site-packages/selectable/templates/cardpayment.html (File does not exist)
As it can be clearly seen, the loader is able to find the template.
The TEMPLATE_DIRS value in settings.py is as follows:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ os.path.join(BASE_DIR, "templates"),],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount',
],
},
},
]
I have tried to move the template to project/templates directory as well but the error persists.
Code checks out with 0 errors/warnings.
contents of cardpayment.html
{% extends "base.html" %}
{% block title %}Card Payments over Phone{% endblock %}
{% block extrahead %}
{% load selectable_tags %}
{% include_ui_theme %}
{% endblock %}
{% block content %}
<h1>Receive Card Payment</h1>
<form name="paymentType" id="paymentType" class="form-horizontal">
<fieldset>
<label>Check type of Customer
<input type="radio" value="existing">Existing Customer<br />
<input type="radio" value="new">Nee Customer<br />
</label>
</fieldset>
</form>
<div class="row">
<form class="form-horizontal">
<table class="table-responsive table-bordered">
{{ form.as_table }}
</table>
</form>
</div>
{% endblock %}
i've been running into the same problem, the solution that work was to specify my template directory (projects/templates) in templates settings like this:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"django.core.context_processors.media",
],
},
},
]
TemplateDoesNotExist... cardpayment.html
might mean Django can't find cardpayment.html
, or it might mean it can find cardpayment.html no problem, but can't find some {% include 'cardpayment_subsection.html' %}
within it.
Explanation:
I got this error just now, in a project that's been working for years, and the other solutions here didn't help me.
My cardpayment.html
was being found by the template loaders, but contained some nonsense which meant it could not be rendered.
The error messages mislead me into thinking Django didn't know the file exists, when in fact it knew it existed, just couldn't successfully render it.
For a while everything was working fine: cardpayment.html
was being rendered without a problem.
views.py
def cardpaymentview(request):
return render_to_response("cardpayment.html", {
"message": "Hi SO"
}, context_instance=RequestContext(request))
Suddenly, even though I hadn't been editing cardpayment.html
, I got that error:
TemplateDoesNotExist at /cardpaymentpage: cardpayment.html
Using loader django.template.loaders.app_directories.Loader:
folder/lib/python2.7/site-packages/django/contrib/admin/templates/cardpayment.html (File does not exist)
folder/project/app1/templates/cardpayment.html (File does not exist)
folder/project/app2/templates/cardpayment.html (File does not exist)
folder/project/paymentapp/templates/cardpayment.html (File exists)
The problem was that my cardpayment.html
in turn has an include
calling another template:
{% include 'cardpayment_subsection.html' %}
I created the error by renaming the file cardpayment_subsection.html
to something_else.html
, without editing cardpayment.html
, so that include
command naturally failed.
But as you can see, the debug message didn't indicate the problem was callling the cardpayment_subsection.html
(file no longer exists).
Summary: if other solutions don't work for you, try creating a test file cardpayment2.html
that simply says "Hello world" and see if you can at least render that instead. Maybe the cardpayment.html
file is being read, but has an error within it. (In my case, I needed to change the {% include '____.html' %}
to refer to a file that actually does exist!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With