s_spirit
s_spirit

Reputation: 115

And again Django can't find template (TemplateDoesNotExist)

I found many topics with such problem, but can't solve my problem with it... So again, please, help to solve it.

Like I said, Django can't find template, but it exist in a "template" dir. And that dir also exist in my "settings.py".

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

As you can see, I tried two different ways. With no success... With all templates in that dir.

As I can see, there is no path to my templates folder in Error Log.

Template-loader postmortem

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
    /Users/slavaspirit/Documents/Django Tests/Test05/testapp/lib/python2.7/site-packages/django/contrib/admin/templates/profile.html (File does not exist)
    /Users/slavaspirit/Documents/Django Tests/Test05/testapp/lib/python2.7/site-packages/django/contrib/auth/templates/profile.html (File does not exist)
    /Users/slavaspirit/Documents/Django Tests/Test05/testapp/lib/python2.7/site-packages/imagekit/templates/profile.html (File does not exist)
    /Users/slavaspirit/Documents/Django Tests/Test05/testapp/lib/python2.7/site-packages/allauth/templates/profile.html (File does not exist)
    /Users/slavaspirit/Documents/Django Tests/Test05/testapp/lib/python2.7/site-packages/allauth/socialaccount/providers/facebook/templates/profile.html (File does not exist)

Full settings list:

"""
Django settings for sisrosta project.

Generated by 'django-admin startproject' using Django 1.8.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

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


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '-7g1@q9b&9ja@&xtuc%q7rk3(uon6z$lb2jr!9jcq84h2_c*fe'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

SITE_ID = 1

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'imagekit',
    'allauth',
    'taggit',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'article',
    'usercard',
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.core.context_processors.tz',
    'django.contrib.messages.context_processors.messages',
    'django.core.context_processors.request',
    'allauth.account.context_processors.account',
    'allauth.socialaccount.context_processors.socialaccount',
)

LOGIN_REDIRECT_URL = '/'

SOCIALACCOUNT_QUERY_EMAIL = True

SOCIALACCOUNT_PROVIDERS = {
    'facebook': {
        'SCOPE': ['email'],
        'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
        'METHOD': 'oauth2',
        'VERIFIED_EMAIL': False
    }
}

ROOT_URLCONF = 'sisrosta.urls'

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',
            ],
        },
    },
]

WSGI_APPLICATION = 'sisrosta.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'test.sqlite3'),
    }
}

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

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'ru-RU'

TIME_ZONE = 'Europe/Moscow'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

THE ANSWER IS: Conflict between TEMPLATES and TEMPLATE_DIRS

Upvotes: 0

Views: 2190

Answers (2)

JordanChina
JordanChina

Reputation: 345

Please double check your template file path and file name. Maybe you can provide file structure of your django folder.

Here is my settings.py about template folder:

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR,'templates'),
    os.path.join(BASE_DIR,'templates','OMS'),
    os.path.join(BASE_DIR,'templates','CRM'),
    os.path.join(BASE_DIR,'templates','PMS'),
    os.path.join(BASE_DIR,'templates','BPS'),
)

and my template structure:

base_template.html  PMS
BPS                 CRM                 OMS

Upvotes: 0

Alan
Alan

Reputation: 307

from Upgrading templates to Django 1.8

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

Upvotes: 1

Related Questions