TemplateDoesNotExist at / base / index.html
I am learning Django and creating a landing page. I am getting TemplateDoesNotExist error and I think I know the reason, but I don’t know how to fix it. my index.html
is in coffeedapp/coffeedapp/templates/base/index.html
However, it looks like Django tried to load the file from
coffeedapp/lib/python2.7/site-packages/django/contrib/admin/templates/base/index.html
Can anyone tell me why this is happening?
I am using Django 1.8.1.
My code is below (for settings.py, I only show codes that I added / changed):
views.py
from django.shortcuts import render
from django.views.generic import TemplateView
class LandingView(TemplateView):
template_name = 'base/index.html'
core / urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
import core.views as coreviews
urlpatterns = patterns('',
url(r'^$', coreviews.LandingView.as_view()),
)
coffeedapp / urls.py
from django.conf.urls import patterns,include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
(r'', include('core.urls')),
)
settings.py
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
MAIN_DIR = os.path.dirname(os.path.dirname(__file__))
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core',
)
ROOT_URLCONF = 'coffeedapp.urls'
WSGI_APPLICATION = 'coffeedapp.wsgi.application'
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
os.path.join(MAIN_DIR,'templates'),
)
STATIC_DIRS= (
os.path.join(MAIN_DIR,'static'),
)
source to share
Which version of Django are you using? Have you set TEMPLATE_DIRS or DIRS to tell Django where to look for templates?
Posting your settings to settings.py, urls.py and views.py will help you get the problem first.
Check out the documentation for template settings for the latest version.
Updates
Remove TEMPLATE_DIRS from settings.py
Add default Django 1.8.x template settings
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(MAIN_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',
],
},
},
]
check for update notes .
source to share