'TemplateDoesNotExist at/

here is my site url http://webtrick.heliohost.org/ my template directory settings:

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__) , 'templates').replace('\\','/')
)

view.py

from django.http import HttpResponse
from django.template import Template , Context
from django.shortcuts import render_to_response
def index(request):
        return render_to_response('index.html')

url.py

from django.conf.urls.defaults import patterns, include, url
from webtrickster.views import index
urlpatterns = patterns('',
    url(r'^$', index)
)

i don't know what's wrong with this code any help appreciated



Solution 1:[1]

 os.path.join(os.path.dirname(__file__) ,'../templates').replace('\\','/')

That worked for me.

Solution 2:[2]

Make sure your Django app is in the INSTALLED_APPS in settings.py. That was my problem with it. So if you have the templates folder in your polls app folder, you need to add the 'polls' at the end of the installed apps in the settings file.

Solution 3:[3]

Add you application into setting.py end of the INSTALLED_APPS like below:

INSTALLED_APPS = [
    ...
    'django.contrib.staticfiles',
    'mysite'                   
  ]

and your templates dir should be in mysite like

mysite
    -settings.py
    -templates/

Solution 4:[4]

I wasted a lot of time trying to figure out what was wrong with my 'templates' directory and found out that :

You may have forgotten to add TEMPLATE_DIR in the following segment of settings.py :

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

So it should have 'DIRS': [TEMPLATE_DIR,], instead of 'DIRS': [],

Also see answers for : TemplateDoesNotExist at /

Solution 5:[5]

First you need to make one folder named 'templates' in your django project folder then, you can add template directory by two ways open your settings file then add any of the following code

1) You can specify your template path directly by

TEMPLATE_DIRS = ( 'D:/Django/web/Kindset/templates' #your file path ,this is my template directory path )

2) Or if you want to use generic path means use

TEMPLATE_DIRS = ( 'os.path.join(BASE_DIR, "templates"),' )

Solution 6:[6]

TEMPLATE_DIRS = ( "mysite/templates" )

TemplateDoesNotExist - file exists, no permissions issue

Solution 7:[7]

My templates folder wasn't a python package because it was missing the __init__.py file. This might have been the reason why Django was not locating my templates.

Solution 8:[8]

Many good answers here, but on updating an old project (nightmare=zinnia, django_cms, AUTH_USER_MODEL = 'accounts.CustomUser') that was not maintained for many moons from django 1.6 to django 1.7 as stage one of a very long process, I found nothing worked. Then I noticed that the errors had quotes around the template it was trying to load:

/home/vagrant/venv/crowd88/local/lib/python2.7/site-packages/djangocms_admin_style/templates/'core/includes/ga.html' (File does not exist)

So I looked at the source and found that quotes are stripped this way:

# lib/python2.7/site-packages/cms/utils/plugins.py
...
template = get_template(force_unicode(node.template).strip('"'))
...

Then I noticed that single quotes were being used in the loaders

{% include core/includes/ga.html' %}

So the fix was

{% include "core/includes/ga.html" %}

using a regex process

Solution 9:[9]

Move your "templates" folder to the main and not in any sub folder. Or on the same level as other projects folder. This might have been the reason why Django was not locating my templates. My project worked after doing this.

Solution 10:[10]

make sure your dirs directory in settings.py looks like this

'DIRS': [os.path.join(BASE_DIR, 'templates')],

Solution 11:[11]

By default, inside the settings.py file, the 'DIRS' array is empty as you can see below.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

So to solve the issue, just add BASE_DIR / 'templates' to the array to look like below. And you are good to go.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / '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',
            ],
        },
    },
]

Solution 12:[12]

Go to the settings.py file and check the TEMPLATES section. Notice the DIR value, by default it should be []. Add "os.path.join(BASE_DIR, 'templates')" inside this. It should look like this :

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, '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',
        ],
    },
},

]

Solution 13:[13]

You may forgot to install you app

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tutorials'
]

Make sure you also add dirs properly in your templates

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, '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',
            ],
        },
    },
]

Solution 14:[14]

I encountered the same error. After checking TEMPLATE_DIR and INSTALLED_APPS a thousand times I noticed a small typo in one .html template:

{% extends "my_app/base.html " %}

should have been

{% extends "my_app/base.html" %}

(notice the white space in the first command)

Solution 15:[15]

If you have tried some of the solutions above and it not worked try checking whether the template is within the correct folder.

Template outside of the templates/appname folder:

appname/
  |
  |__templates/
  |  |
  |  |__appname/
  |     |__appname_form.html
  |__appname_list.html <------ outside of the appname/ folder (WRONG)

Like this if you have a url that send to this template, Django will through a TemplateDoesNotExist since the template does not follow the path you placed in TEMPLATES.DIRS.

Try fixing like:

Template inside of the templates/appname folder:

appname/
  |
  |__templates/
  |  |
  |  |__appname/
  |     |__appname_form.html
  |     |__appname_list.html <------ inside of the appname/ folder (RIGHT)

Therefore, like this you may fix this exception.