TemplateDoesNotExist - even though the template is in the correct folder

2010-06-05 Thread elysianfields
I did see a very similar post in this group, but it did not help me
with my problem. I'm probably overlooking something simple, this is
what I have:


# SETTINGS.PY:
TEMPLATE_DIRS = (
"D:/django-projects/localsite/templates",
)


# POLLS/VIEWS.PY:
from django.http import HttpResponse
from localsite.polls.models import Poll
from django.template import Context, loader

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


THE FOLDER STRUCTURE:
D:\django-projects\localsite\templates\polls\index.htm


Notes:
- I also tried editing the admin template by creating D:\django-
projects\localsite\templates\admin\base_site.html but changing that
template did not affect the admin interface either.
- I am running this on the django development server. The
TemplateDoesNotExist error page is a result of trying to access
http://localhost:8000/polls/
- More info from the error page:

Request Method: GET
Request URL:http://localhost:8000/polls/
Django Version: 1.2.1
Exception Type: TemplateDoesNotExist
Exception Value:polls/index.htm
Exception Location: /usr/lib/python2.5/site-packages/django/template/
loader.py in find_template, line 138

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:

Any suggestions would be appreciated. Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: TemplateDoesNotExist - even though the template is in the correct folder

2010-06-05 Thread elysianfields
Well, after inserting a number of debugging statements in loader.py
and filesystem.py, I found the cause of this; here's what the
filesystem.py Loader's load_template_source attempts to access:

filepath=u'/cygdrive/d/django-projects/localsite/D:/django-projects/
localsite/templates/polls/index.htm'

So if you're using windows and have python installed through cygwin,
you have to edit the loader files a bit. By the way, I also have
python installed outside of cygwin and never realized that django
decided to use the cygwin python directory... I'm not sure if that can
be changed and how. Thoughts?



On Jun 5, 4:16 pm, elysianfields  wrote:
> I did see a very similar post in this group, but it did not help me
> with my problem. I'm probably overlooking something simple, this is
> what I have:
>
> # SETTINGS.PY:
> TEMPLATE_DIRS = (
>     "D:/django-projects/localsite/templates",
> )
>
> # POLLS/VIEWS.PY:
> from django.http import HttpResponse
> from localsite.polls.models import Poll
> from django.template import Context, loader
>
> def index(request):
>     latest_polls = Poll.objects.all().order_by('-pub_date')[:5]
>     t = loader.get_template('polls/index.htm')
>     c = Context({
>         'latest_polls': latest_polls,
>     })
>     return HttpResponse(t.render(c))
>
> THE FOLDER STRUCTURE:
> D:\django-projects\localsite\templates\polls\index.htm
>
> Notes:
> - I also tried editing the admin template by creating D:\django-
> projects\localsite\templates\admin\base_site.html but changing that
> template did not affect the admin interface either.
> - I am running this on the django development server. The
> TemplateDoesNotExist error page is a result of trying to 
> accesshttp://localhost:8000/polls/
> - More info from the error page:
>
> Request Method:         GET
> Request URL:            http://localhost:8000/polls/
> Django Version:         1.2.1
> Exception Type:         TemplateDoesNotExist
> Exception Value:        polls/index.htm
> Exception Location:     /usr/lib/python2.5/site-packages/django/template/
> loader.py in find_template, line 138
>
> 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:
>
> Any suggestions would be appreciated. Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: TemplateDoesNotExist - even though the template is in the correct folder

2010-06-05 Thread elysianfields
I'm talking to myself here, but in case someone else runs into the
same problem, I'll summarize the cause & solution I used (although
it's only a hack, I don't know if it will work consistently):

Cause: If you have Python installed through Cygwin on Windows, Django
is using the Cygwin path, which messes up the templates directory
path. Example: instead of "D:/django-projects/localsite/templates/
polls/index.htm", the path reads "/cygdrive/d/django-projects/
localsite/D:/django-projects/localsite/templates/polls/index.htm".

Solution:

Edit the following file: path\to\Cygwin\lib\python2.5\site-packages
\django\template\loaders\filesystem.py

1) At the top of the file, add the line:

import os.path

2) In function get_template_sources, change the following line:

 yield safe_join(template_dir, template_name)

to the following:

yield os.path.join(template_dir, template_name)

This solved the issue for me. A better fix would be to make Django use
Python directly through Windows, not through Cygwin, but I'm not sure
how to set it up now that it's already installed.

Cheers.

On Jun 5, 5:40 pm, elysianfields  wrote:
> Well, after inserting a number of debugging statements in loader.py
> and filesystem.py, I found the cause of this; here's what the
> filesystem.py Loader's load_template_source attempts to access:
>
> filepath=u'/cygdrive/d/django-projects/localsite/D:/django-projects/
> localsite/templates/polls/index.htm'
>
> So if you're using windows and have python installed through cygwin,
> you have to edit the loader files a bit. By the way, I also have
> python installed outside of cygwin and never realized that django
> decided to use the cygwin python directory... I'm not sure if that can
> be changed and how. Thoughts?
>
> On Jun 5, 4:16 pm, elysianfields  wrote:
>
> > I did see a very similar post in this group, but it did not help me
> > with my problem. I'm probably overlooking something simple, this is
> > what I have:
>
> > # SETTINGS.PY:
> > TEMPLATE_DIRS = (
> >     "D:/django-projects/localsite/templates",
> > )
>
> > # POLLS/VIEWS.PY:
> > from django.http import HttpResponse
> > from localsite.polls.models import Poll
> > from django.template import Context, loader
>
> > def index(request):
> >     latest_polls = Poll.objects.all().order_by('-pub_date')[:5]
> >     t = loader.get_template('polls/index.htm')
> >     c = Context({
> >         'latest_polls': latest_polls,
> >     })
> >     return HttpResponse(t.render(c))
>
> > THE FOLDER STRUCTURE:
> > D:\django-projects\localsite\templates\polls\index.htm
>
> > Notes:
> > - I also tried editing the admin template by creating D:\django-
> > projects\localsite\templates\admin\base_site.html but changing that
> > template did not affect the admin interface either.
> > - I am running this on the django development server. The
> > TemplateDoesNotExist error page is a result of trying to 
> > accesshttp://localhost:8000/polls/
> > - More info from the error page:
>
> > Request Method:         GET
> > Request URL:            http://localhost:8000/polls/
> > Django Version:         1.2.1
> > Exception Type:         TemplateDoesNotExist
> > Exception Value:        polls/index.htm
> > Exception Location:     /usr/lib/python2.5/site-packages/django/template/
> > loader.py in find_template, line 138
>
> > 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:
>
> > Any suggestions would be appreciated. Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.