5

I know many people have asked, this question, but despite hardcoding the path to my template directory I can't seem to get Django to find my template.

Here is settings.py

TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
#django.template.loaders.eggs.Loader',
)

TEMPLATE_DIRS = (
    "/Users/full/path/to/marketing_site/templates",
)

This is the views.py file:

def static (request, feature_page):

# this will get the appropriate feature page template.
template = loader.get_template('features/pricing.html')
c = RequestContext(request,{
})
return HttpResponse(template.render(c))

Inside the main folder is the templates folder and the app folder. I use to put the apps in the same folder as settings.py but it appears django 1.4 has changed the default file structure.

My error is:

TemplateDoesNotExist at /features/pricing 

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/Library/Python/2.7/site-packages/django/contrib/auth/templates/feature_pricing.html (File does not exist)

Update:
My logs for the webpage list the TEMPLATE_DIRS as ().

If I put a print statement on the settings.py page for the TEMPLATE_DIRS I get a printout of the TEMPLATE_DIRS appropriately... so somehow the TEMPLATE_DIRS isn't being used (from what it looks like)

Christopher H
  • 2,044
  • 6
  • 24
  • 30

4 Answers4

9

I had added in an extra TEMPLATE_DIR in the settings.py

:(

Christopher H
  • 2,044
  • 6
  • 24
  • 30
  • Argh! Just found out my problem was the same. It had stopped work for a good couple of days... :D – avramov Oct 11 '12 at 07:05
5

it's better to set up relative paths for your path variables. You can set it up like so:

import os

PATH_PROJECT = os.path.realpath(os.path.dirname(__file__))

...

...

TEMPLATE_DIRS = (
    PATH_PROJECT + '/templates/'
)

Also assuming you are using windows you may want to try:

TEMPLATE_DIRS = (
"C:/Users/full/path/to/marketing_site/templates",
)
Frantz Romain
  • 836
  • 1
  • 6
  • 14
1

I'm betting /Users/full/path/to/marketing_site/templates does not contain a features directory, or /Users/full/path/to/marketing_site/templates/features does not contain a pricing.html file.

Based on your comment, it looks like you're calling loader.get_template('feature_pricing.‌​html'), instead of using 'feature/pricing.html'.

EDIT: I didn't notice this before:

Inside the main folder is the templates folder and the app folder. I use to put the apps in the same folder as settings.py but it appears django 1.4 has changed the default file structure.

That could be causing the issue. Change the directory structure to match the 1.4 Django conventions. You might just recreate the project, copy the relevant settings over into the newly create settings.py, and copy all the files.

Colin Dunklau
  • 3,001
  • 1
  • 20
  • 19
  • 1
    directory and permissions are ok... the route exists... here is more to the error code: Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader: /Library/Python/2.7/site-packages/django/contrib/auth/templates/feature_pricing.html (File does not exist) – Christopher H Jul 10 '12 at 22:06
1

Try adding project paths to django.wsgi

import os
import sys

paths = ('path/to/project/',
        'path/to/more /included/directories/',
    )

for path in paths:
    if path not in sys.path:
       sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Priyeshj
  • 1,295
  • 2
  • 17
  • 32