I'm doing the Django tutorial here: http://docs.djangoproject.com/en/1.2/intro/tutorial03/
My TEMPLATE_DIRS in the settings.py looks like this:
TEMPLATE_DIRS = (
"/webapp2/templates/"
"/webapp2/templates/polls"
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
My urls.py looks like this:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(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<poll_id>\d+)/vote/$', 'polls.views.vote'),
(r'^admin/', include(admin.site.urls)),
)
My views.py looks like this:
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('c:/webapp2/templates/polls/index.html')
c = Context({
'latest_poll_list': latest_poll_list,
})
return HttpResponse(t.render(c))
I think I am getting the path of my template wrong because when I simplify the views.py code to something like this, I am able to load the page.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the poll index.")
My index template file is located at C:/webapp2/templates/polls/index.html. What am I doing wrong?