2

I know there are lots of these questions already but I haven't been able to find an answer. I'm trying to get my homepage to load but I have been getting this error:

Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.7.1
Exception Type: TemplateDoesNotExist
Exception Value:    
base.html
Exception Location: /Users/user/.virtualenvs/screen_savers/lib/python3.4/site-packages/django/template/loader.py in find_template, line 136
Python Executable:  /Users/user/.virtualenvs/screen_savers/bin/python
Python Version: 3.4.1
Python Path:    
['/Users/user/Devspace/scren_savers/the_screen_savers',
 '/Users/user/.virtualenvs/screen_savers/lib/python34.zip',
 '/Users/user/.virtualenvs/screen_savers/lib/python3.4',
 '/Users/user/.virtualenvs/screen_savers/lib/python3.4/plat-darwin',
 '/Users/user/.virtualenvs/screen_savers/lib/python3.4/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
 '/Users/user/.virtualenvs/screen_savers/lib/python3.4/site-packages']

and can't seem to figure out why. I specified my TEMPLATE_DIR properly in my settings.py and made sure that the file exists where is says it does. I have also looked through all of these questions where people had the same problem but none of them solved my problem:

Django App template Loader, can't find app templates

Django template Path

Django can't find template

Django TemplateDoesNotExist?

Template does not exist

Django cant find templates

What really confuses me is that if I check the value of BASE_DIR and TEMPLATE_DIR it gives me:

/Users/user/Devspace/scren_savers/the_screen_savers /Users/user/Devspace/scren_savers/the_screen_savers/templates

respectively which is exactly what I expect to see. It seems like it knows where the templates are but still can't see them. Any help would be greatly appreciated.

Also an additional, less important question:

I have seen BASE_DIR + '/templates' and os.path.join(BASE_DIR, "templates") suggested as the proper way to specify the TEMPLATE_DIR. Is one of these better than the other (if so why) or is this just a matter of personal preference?

Here is the view that I am trying to load:

from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic import View

class home_page(View):

    def get(self, request):
       return render(request, 'base.html')

and here is my settings file:

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

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

TEMPLATE_DIR =  (
    BASE_DIR +  "/templates/",
)

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


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

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'screen_savers',
)

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

ROOT_URLCONF = 'screen_savers.urls'

WSGI_APPLICATION = 'screen_savers.wsgi.application'


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

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

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
Community
  • 1
  • 1
user3282276
  • 3,674
  • 8
  • 32
  • 48

1 Answers1

5

You should change in file settings.py TEMPLATE_DIR to TEMPLATE_DIRS.

jrafa
  • 66
  • 2