Thursday, March 29, 2012

Template file not recognized for some strange reason

I'm working through one of the template examples in the django book
and the template file I created isn't being recognized for some reason
even though it's in the folder. The error report is at the bottom of
the page. The TEMP_DIRS variable is set to the correct file path in my
settings file: TEMPLATE_DIRS = ("/Users/Documents/Music\ App/redlab/
The view function is in order too:

from django.template.loader import get_template
from django.template import Context
from django.http import HttpResponse
import datetime
def current_datetime(request):
now =
t = get_template('current_datetime.html')
html = t.render(Context({'current_date':now}))
return HttpResponse(html)

The url file is also in order:

from django.conf.urls.defaults import*
from redlab.views import current_datetime
urlpatterns = patterns('', (r'^time/$', current_datetime))

And there is a current_datetime.html file in the templates directory
with the following code in it:
<html><body>It is now {{ current_date }}.</body></html>

But the file isn't being recognized for some reason. Please advise.

Request Method: GET
Request URL:
Django Version: 1.3.1
Python Version: 2.7.2
Installed Applications:
Installed Middleware:

Template Loader Error:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/Users/Documents/Music\ App/redlab/templates/current_datetime.html
(File does not exist)
Using loader django.template.loaders.app_directories.Loader:

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
site-packages/django/core/handlers/" in get_response
111. response = callback(request,
*callback_args, **callback_kwargs)
File "/Users/mikaschiller/Documents/Music App/redlab/../redlab/" in current_datetime
11. t = get_template('current_datetime.html')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
site-packages/django/template/" in get_template
157. template, origin = find_template(template_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
site-packages/django/template/" in find_template
138. raise TemplateDoesNotExist(name)

Exception Type: TemplateDoesNotExist at /time/
Exception Value: current_datetime.html

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment