Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TemplateDoesNotExist at / base/index.html

Tags:

python

django

I'm learning Django and am building a landing page. I get the TemplateDoesNotExist error and I think I know the reason but I don't know how to fix this. my index.html is in coffeedapp/coffeedapp/templates/base/index.html However it seems like Django tried to load the file from

coffeedapp/lib/python2.7/site-packages/django/contrib/admin/templates/base/index.html Could someone tell me why this is happening?

I use Django 1.8.1.

My code is below (for settings.py, I only show codes that I added/modified):

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'),
)
like image 517
user3368526 Avatar asked Mar 11 '26 21:03

user3368526


1 Answers

Which version of Django you are using? Have you setup TEMPLATE_DIRS or DIRS to instruct Django where to look for templates?

Posting your settings.py, urls.py and views.py will help to get the issue at first place.

Have a look at the documentation for template settings for latest version.

updates

Remove TEMPLATE_DIRS from settings.py

Add standard 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 update notes.

like image 98
moonstruck Avatar answered Mar 14 '26 11:03

moonstruck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!