开发者

Is Django lying to me?! render_to_response function returns TemplateDoesNotExist when the file does indeed exist

OK. I have read many other accounts of this happening, and they were always solved when the question asker correctly modified their TEMPLATE_DIRS setting. None of these suggestions have worked for me. The strange thing is that the template loads when using the Django web server, but errors out when using mod_wsgi. I think django is maybe throwing an incorrect exception, because the TemplateDoesNotExist error simply can not apply given my settings.

My code:

my app/views/view.py (yes, i have my views in a subfolder)

  8 def index(request):
  9     return render_to_response('pages/home/base_home.html')

Here is my settings.py located at root (standard location)

106 TEMPLATE_DIRS = (
107     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
108     # Always use forward slashes, even on Windows.
109     # Don't forget to use absolute paths, not relative paths.
110     "/home/foobar/templates",
111 )

And finally, here is my view located at /home/foobar/templates/pages/home/

  1 {% extends 'base.html' %}
  2 
  3 {% block navigation %}
  4     {% include 'modules/navigation/navigation.html' %}
  5 {% endblock %}
  6 
  7 {% block slideshow %}
  8     开发者_开发问答{% include 'modules/slideshow/slideshow.html' %}
  9 {% endblock %}

Also, here is an ls -l proving that the file does exist

foo@bar:~$ ls -l templates/pages/home/
total 12
-rwxr-xr-x 1 foo foo 205 2011-06-05 12:37 base_home.html
foo@bar:~$ 

Here is the postmortem report that Django gives me:

Template-loader postmortem

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/home/foobar/templates/pages/home/base_home.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
/usr/local/lib/python2.6/dist-packages/django/contrib/admin/templates/pages/home/base_home.html (File does not exist)

edit

Here is my wsgi file

  3 import os
  4 import sys
  5 
  6 path = '/media/PENDRIVE/Projects/'
  7 if path not in sys.path:
  8     sys.path.append(path)
  9     
 10 os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
 11 
 12 import django.core.handlers.wsgi
 13 application = django.core.handlers.wsgi.WSGIHandler()
 14 

Thank you for any insight, as I am baffled and stuck!


You should check if the template folder is readable by the user the wsgi process runs with. I suppose this is a simple permission problem.


You're not including the correct url. It should be "pages/home/modules/navigation/navigation.html"


this should be solved by replacing the full path of BASE_DIR in the settings.py

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': ['/var/www/assistance/templates','templates'],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},
]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜