Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django can't find template

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)

like image 791
Christopher H Avatar asked Jul 10 '12 21:07

Christopher H


2 Answers

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

:(

like image 174
Christopher H Avatar answered Sep 27 '22 22:09

Christopher H


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",
)
like image 40
Frantz Romain Avatar answered Sep 27 '22 22:09

Frantz Romain