Kevin
Kevin

Reputation: 4361

Django Template Issue

I am following along on this tutorial, after I add the templates and put the pattern in urls.py, I go the website I get a template not loaded page.

This is my template dirs section from settings.py:

TEMPLATE_DIRS = (
    "/home/django-projects/base/templates/",
)

the base folder hierarchy is this:

blog<dir>
dbs<dir>
__init__.py
manage.py
settings.py
templates<dir>
urls.py

urls.py looks like this:

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('base.blog.views',
    (r"", "main"),
    # Example:
    # (r'^base/', include('base.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
)

In templates I have a folder called blog, and it contains the two html files from the tutorial. I am just not sure what setting I am missing to display the proper templates. I will be happy to post anything else you would need to see. I am sure it is something trivial, I just can't seem to figure out what it is. Thanks for your help.

EDIT So I was playing around with it, and I realized I couldn't get to admin. So I uncoupled the urls for the blog part away from the main. The urls.py on the top level looks like this:

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'blog/', include('blog.urls')),
    # Example:
    # (r'^base/', include('base.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
)

And in the blog folder urls.py looks like this: from django.conf.urls.defaults import *

urlpatterns = patterns('base.blog.views',
    (r'^$', 'main'),
)

Now I can get to admin, but still get a template load error when I try to get to the blog.

TemplateDoesNotExist at /blog/
blog/list.html
Request Method: GET
Request URL:    http://192.168.1.124:9999/blog/
Django Version: 1.2.3
Exception Type: TemplateDoesNotExist
Exception Value:    
blog/list.html
Exception Location: /usr/local/lib/python2.6/dist-packages/Django-1.2.3-py2.6.egg/django/template/loader.py in find_template, line 138
Python Executable:  /usr/bin/python
Python Version: 2.6.6
Python Path:    ['/home/kevin/django-projects/base', '/usr/local/lib/python2.6/dist-packages/setuptools-0.6c11-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/BeautifulSoup-3.1.0.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/Django-1.2.3-py2.6.egg', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.6/gtk-2.0']
Server time:    Tue, 2 Nov 2010 11:59:13 -0500

Template-loader postmortem

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:

Upvotes: 1

Views: 2643

Answers (2)

Evan Porter
Evan Porter

Reputation: 2977

Should the last line of the "main" view contain "blog/list.html" instead of "list.html"?

Try replacing that line with the following:

return render_to_response("blog/list.html", dict(posts=posts, user=request.user))

Do the same thing with the "post" view.

Basically, Django is going to look under each of the configured template directories in settings.py and if you specify "list.html" it better be in the root of of of those directories. Since you put the "list.html" in the "blog" sub-directory and not where you told it to look, Django can't find it.

Upvotes: 2

Antoine Pelisse
Antoine Pelisse

Reputation: 13129

First, you have a missing leading / in your template directory:

TEMPLATE_DIRS = (
    "/home/django-projects/base/templates/",
)

Upvotes: 0

Related Questions