[Fixed]-Django Template Not Found

1👍

So it turns out my problem was not with Django itself but with my environment. I was running the Django server from ~/Django-project, and our dev server encrypts home directories once all sessions are signed out which means the service could no longer find it. Moving the project to /var/ and daemonizing the manage.py runserver command has kept the project free of Template Does Not Exist errors.

49👍

Just wanted to add another case where you may get the Template Does Not Exist error.

Make sure you’ve added your app in the INSTALLED_APPS variable inside your settings.py file. The startapp command is not enough.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myappname', # add your app here :)
]

I know it’s silly, but I know people that have failed their driver’s test because of forgetting to fasten their seat belt, so forgetting a line of code isn’t as rare as it sounds.

8👍

Try updating your settings like so:

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, 'templates'),)

(This is the default way of getting the BASE_DIR in django 1.8). Prior to Python 3.4, __file__ is not guaranteed to give the absolute file path.

You should also try and remain platform agnostic by using os.path.join rather than adding the directory as a string (other platforms use backslashes).

Leave a comment