Template Loader Error: (It's been really frustrating till now..!)

104 views
Skip to first unread message

Tony Kyriakides

unread,
Jan 25, 2012, 9:51:34 AM1/25/12
to Django users
Hey all... i get this error while i have a template directory and my
about.html file.... It doesn't display the home.html either...

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/about/

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:
/home/tony/Documents/blog/blog/templates/about.html (File does not
exist)
Using loader django.template.loaders.app_directories.Loader:



Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/
base.py" in get_response
111. response = callback(request,
*callback_args, **callback_kwargs)
File "/home/tony/Documents/blog/../blog/views.py" in about
9. return render_to_response('about.html',)
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts/
__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args,
**kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/template/
loader.py" in render_to_string
181. t = get_template(template_name)
File "/usr/local/lib/python2.7/dist-packages/django/template/
loader.py" in get_template
157. template, origin = find_template(template_name)
File "/usr/local/lib/python2.7/dist-packages/django/template/
loader.py" in find_template
138. raise TemplateDoesNotExist(name)

Exception Type: TemplateDoesNotExist at /about/
Exception Value: about.html

Anoop Thomas Mathew

unread,
Jul 19, 2012, 1:18:12 AM7/19/12
to django...@googlegroups.com

On 19 July 2012 04:46, Mark Anderko <mand...@google.com> wrote:
I am having similar problems. did you manage to get this fixed?


make sure that /home/tony/Documents/blog/blog/templates/about.html exist. Else, add templates directory to the TEMPLATE_DIRS.


Using loader django.template.loaders.app_directories.Loader:



Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/
base.py" in get_response
  111.                         response = callback(request,
*callback_args, **callback_kwargs)
File "/home/tony/Documents/blog/../blog/views.py" in about
  9.          return render_to_response('about.html',)
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts/
__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args,
**kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/template/
loader.py" in render_to_string
  181.         t = get_template(template_name)
File "/usr/local/lib/python2.7/dist-packages/django/template/
loader.py" in get_template
  157.     template, origin = find_template(template_name)
File "/usr/local/lib/python2.7/dist-packages/django/template/
loader.py" in find_template
  138.     raise TemplateDoesNotExist(name)

Exception Type: TemplateDoesNotExist at /about/
Exception Value: about.html

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/b7u_nPwieJMJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Thomas Orozco

unread,
Jul 19, 2012, 2:54:35 AM7/19/12
to django...@googlegroups.com

You can also have a "templates"  directory in any app of yours and Django will pick them up from there.

It's also best practice to start your template path with your app name. For instance: myapp/templates/myapp/my template.html
Or; mytemplatedir/myapp/mytemplate.html

Indeed  django does not elect to use templates from a given app over another, so if two apps have a template with the same name, you're in trouble.
Only the templates from your Template dirs have higher priority.

This also makes overriding templates easier should you decide to redistribute your app, as one can have a myapp directory in their template dir to override your templates, as templates from this folder will have higher priority than those from the App dir.

Reply all
Reply to author
Forward
0 new messages