Wednesday, February 29, 2012

Re: Error on Tutorial Part 3 - https://docs.djangoproject.com/en/1.3/intro/tutorial03/

Try:
'C:\Python27\my_Djando_projects\mysite\My_Templates\polls\index.html'
'C:\Python27\my_Djando_projects\mysite\My_Templates\polls\'
'C:\Python27\my_Djando_projects\mysite\My_Templates\'

Or:
abspath = lambda *p: os.path.abspath(os.path.join(*p))
PROJECT_ROOT = abspath(os.path.dirname(__file__))
(...)
TEMPLATE_DIRS = (abspath(PROJECT_ROOT, "My_Templates"),)




2012/2/29 Sami Balbaky <sami.balbaky@gmail.com>
Hi Anoop,

Thank you for the kind reply, I've tried that already. Here are the 3 variations that I've attempted so far within settings.py in TEMPLATE_DIRS:

'C:/Python27/my_Djando_projects/mysite/My_Templates/polls/index.html'
'C:/Python27/my_Djando_projects/mysite/My_Templates/polls/'
'C:/Python27/my_Djando_projects/mysite/My_Templates/'


They all yield the same error unfortunately. I'm coding this on a Windows Vista system, fyi.

Best,

SB


On Wed, Feb 29, 2012 at 11:48 AM, Anoop Thomas Mathew <atmb4u@gmail.com> wrote:
You have to give template directories, not template names in the settings.py.
Thanks,
Anoop
atm
___
Life is short, Live it hard.





On 1 March 2012 01:16, Django_for_SB <sami.balbaky@gmail.com> wrote:
Hello All,

I'm going through the tutorial on djangoproject.com, and can't seem to
hurdle over this section that reads "Write views that actually do
something"

Here's the code I have so far, which is directly copied from the
tutorial or prescribed by the tutorial:

views.py:
"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))"



settings.py:
"...
TEMPLATE_DIRS = (
   # 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.
   'C:/Python27/my_Djando_projects/mysite/My_Templates/admin/
base_site.html'
   'C:/Python27/my_Djando_projects/mysite/My_Templates/admin/
index.html'
   'C:/Python27/my_Djando_projects/mysite/My_Templates/polls/
index.html'
)
..."


index.html:
"{% if latest_poll_list %}
   <ul>
   {% for poll in latest_poll_list %}
       <li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></
li>
   {% endfor %}
   </ul>
{% else %}
   <p>No polls are available.</p>
{% endif %}
"




I keep getting the same error, which reads:


TemplateDoesNotExist at /polls/

polls/index.html

Request Method:         GET
Request URL:            http://localhost:8000/polls/
Django Version:                 1.3.1
Exception Type:         TemplateDoesNotExist
Exception Value:

polls/index.html

Exception Location:     C:\Python27\lib\site-packages\django\template
\loader.py in find_template, line 138
Python Executable:      C:\Python27\python.exe
Python Version:         2.7.2
Python Path:

['C:\\Python27\\my_Djando_projects\\mysite',
 'C:\\Windows\\system32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages']

Server time:    Wed, 29 Feb 2012 11:32:54 -0800
Template-loader postmortem

Django tried loading these templates, in this order:

Using loader django.template.loaders.filesystem.Loader:
c:\python27\my_djando_projects\mysite\my_templates\admin
\base_site.html
c:\python27\my_djando_projects\mysite\my_templates\admin\index.html
c:\python27\my_djando_projects\mysite\my_templates\polls\index.html
\polls\index.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
c:\python27\lib\site-packages\django\contrib\admin\templates\polls
\index.html (File does not exist)




What on earth am I doing wrong here? I've so many different variations
of my settings.py, views.py, and index.html. Any help would be much
appreciated.


Thanks,

SB

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



--
Sami Balbaky
System Engineer - Ultrawave Labs


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