Wednesday, July 18, 2012

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

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.

Le 19 juil. 2012 07:18, "Anoop Thomas Mathew" <atmb4u@gmail.com> a écrit :

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


On Wednesday, January 25, 2012 6:51:34 AM UTC-8, leaks wrote:
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)


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-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.

--
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.

--
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