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/
templates",)
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 = datetime.datetime.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.
thnx.

Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/time/
Django Version: 1.3.1
Python Version: 2.7.2
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')

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:

Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request,
*callback_args, **callback_kwargs)
File "/Users/mikaschiller/Documents/Music App/redlab/../redlab/
views.py" 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/loader.py" 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/loader.py" 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 django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment