Tutorial Error - TemplateDoesNotExist at /polls/

1,368 views
Skip to first unread message

TheNational22

unread,
Oct 21, 2010, 1:59:49 PM10/21/10
to Django users
I searched the posts for this, but I couldn't find my issue. I am
getting TemplateDoesNotExist at /polls/ when after adding the
index.html, but the template loaders show no directory being loaded.
My traceback is here http://dpaste.com/261308/. Thanks for the input.

Robbington

unread,
Oct 21, 2010, 2:43:15 PM10/21/10
to Django users
Where is your template_dirs in settings.py pointed too?
If you can post your urls.py.

Looking at the tutorial again,

(r'^polls/$', 'polls.views.index'), means that the url 'polls' will
serve the index function in the views.py file inside your polls app.
Your index.html should lie inside the top level of your templates
directory and will serve what ever you set as your top level domain
name, or http://192.168.1.131:9999/ of course you have to set that up
in your urls.py

I use urlpatterns = patterns('django.views.generic.simple',
(r'^$', 'direct_to_template',{'template': 'index.html'}),

and then you would have

(r'polls/$ , ('polls.view.index')

TheNational22

unread,
Oct 21, 2010, 3:26:33 PM10/21/10
to Django users
The index.html file is in the right location, what worries me is that
the template loaders are showing that they are loading nothing. In all
the other qustion in the google groups here that referenced an isssue
with templates not loading, their traceback had something like unable
to find documnet at c:\blah\blah\tmplates. Mine is empty. All the
files have the same owner, but nothing is loading.

My template_dir is pointed to /home/me/Templates and I have tried it
with with index.html being in there and in a dir called polls/, same
thing no matter what

Urls.py
GNU nano 2.2.4 File: urls.py

from django.conf.urls.defaults import *

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

urlpatterns = patterns('',
# Example:
# (r'^tutorial/', include('tutorial.foo.urls')),
(r'^polls/$', 'polls.views.index'),
(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
(r'^polls/(?P<polls_id>\d+)/vote/$', 'polls.views.vote'),
# 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)),
)


On Oct 21, 2:43 pm, Robbington <robbing...@hotmail.co.uk> wrote:
> Where is your template_dirs in settings.py pointed too?
> If you can post your urls.py.
>
> Looking at the tutorial again,
>
> (r'^polls/$', 'polls.views.index'), means that the url 'polls' will
> serve the index function in the views.py file inside your polls app.
> Your index.html should lie inside the top level of your templates
> directory and will serve what ever you set as your top level domain
> name, orhttp://192.168.1.131:9999/of course you have to set that up

Robbington

unread,
Oct 21, 2010, 4:09:17 PM10/21/10
to Django users
You see, what I tried to explain in the last message, my friend was
that index in 'polls.views.index') doesnt point the url polls/ to the
index.html but to the function you are suppose to create in the
views.py file in your app directory.

Your view.py file (inside your poll app folder)should look like

from django.http import HttpResponse

def index(request):
return HttpResponse("Hello world blah blah blah")

I can see that its a bit confusing.

Rob

TheNational22

unread,
Oct 21, 2010, 4:35:12 PM10/21/10
to Django users
I fully understood that and I thought it was implied in that I said I
was working with the tutorial I would have that file created. You only
asked where my template dir was directed to and that I put urls.py in
my reply, I would have put this in there if you had requested. Here it
is. Now, as far as I understand you only have to put the path in the
loader form the end of the template_dirs variable. Do I have to put
the abs path or do I have another issue.


GNU nano 2.2.4 File: views.py

# Create your views here.
from django.template import Context, loader
from polls.models import Poll
from django.http import HttpResponse

def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
t = loader.get_template('polls/index.html')
c = Context({
'latest_poll_list': latest_poll_list,
})
return HttpResponse(t.render(c))

def detail(request, poll_id):
return HttpResponse("You are viewing Poll %s." % poll_id)

def results(request, poll_id):
return HttpResponse("You are looking the results of Poll %s." %
poll_id)

[ Read 23 lines ]

Robbington

unread,
Oct 21, 2010, 5:05:54 PM10/21/10
to Django users
Apologies, I wasnt sure which bit of the tutorial you where at. I
think I see now the problem. Did you just stop reading after you
entered the last bit of code in views.py?

"""Reload the page. Now you'll see an error:

TemplateDoesNotExist at /polls/"""

So index.html is in /home/me/Templates/polls/index.html ?

Where template_DIR is "/home/me/Templates"
Reply all
Reply to author
Forward
0 new messages