Jackson Flint-Gonzales
Jackson Flint-Gonzales

Reputation: 482

Django, TemplateDoesNotExist error: Heroku can't find template directory. How to show it where to look?

I've done much clicking and syncdb'ing and have yet to find a solution. I get this error:

TemplateDoesNotExist at /quotes/
quotes/index.html
Request Method: GET
Request URL:    http://quoteboard94.herokuapp.com/quotes/
Django Version: 1.4.4 
Exception Type: TemplateDoesNotExist
Exception Value:    
quotes/index.html
Exception Location: /app/.heroku/python/lib/python2.7/site-packages/django/template/loader.py in find_template, line 138
Python Executable:  /app/.heroku/python/bin/python
Python Version: 2.7.3
Python Path:    
['/app',
 '/app/.heroku/python/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
 '/app',
 '/app/.heroku/python/lib/python27.zip',
 '/app/.heroku/python/lib/python2.7',
 '/app/.heroku/python/lib/python2.7/plat-linux2',
 '/app/.heroku/python/lib/python2.7/lib-tk',
 '/app/.heroku/python/lib/python2.7/lib-old',
 '/app/.heroku/python/lib/python2.7/lib-dynload',
 '/app/.heroku/python/lib/python2.7/site-packages',
 '/app/.heroku/python/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']

My settings have this:

PROJECT_DIR = os.path.dirname(__file__) #for heroku

TEMPLATE_DIRS = (
    os.path.join(PROJECT_DIR, '/templates/'), # for heroku
    '/Users/jacksongonzales/projects/QuoteBoard/templates/',
)

import os.path is up top as well.

That path under TEMPLATE_DIRS is the absolute path to my templates.

Am I not punching in the right stuff for PROJECT_DIR and TEMPLATE_DIRS variables?

Upvotes: 2

Views: 1938

Answers (2)

dm03514
dm03514

Reputation: 55962

I believe it should be

os.path.join(PROJECT_DIR, 'templates'), # for heroku

without the slashes.

os.path.join(PROJECT_DIR, '/templates/'), # for heroku

returns /templates/ not the path you would expect

from the docs:

If any component is an absolute path, all previous components (on Windows, including the previous drive letter, if there was one) are thrown away, and joining continues.

Upvotes: 3

Cole
Cole

Reputation: 2509

Here is my set up for a heroku project.

# here() gives us file paths from the root of the system to the directory
# holding the current file.
here = lambda * x: os.path.join(os.path.abspath(os.path.dirname(__file__)), *x)

PROJECT_ROOT = here("..")
# root() gives us file paths from the root of the system to whatever
# folder(s) we pass it starting at the parent directory of the current file.
root = lambda * x: os.path.join(os.path.abspath(PROJECT_ROOT), *x)

....

TEMPLATE_DIRS = (
    root('templates'),
)

UPDATE: My project has the same local template structure as the one it's deployed with, so I don't need to add a direct path in my templates directory. You have one in yours:

'/Users/jacksongonzales/projects/QuoteBoard/templates/',

If your first entry in your TEMPLATE_DIRS is correct, do you need the second one?

Upvotes: 2

Related Questions