Python Django can';找不到模板,文件存在并且指定了模板目录

Python Django can';找不到模板,文件存在并且指定了模板目录,python,django,templates,django-templates,Python,Django,Templates,Django Templates,我知道已经有很多这样的问题了,但我还没有找到答案。我正在尝试加载我的主页,但出现以下错误: 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_sav

我知道已经有很多这样的问题了,但我还没有找到答案。我正在尝试加载我的主页,但出现以下错误:

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']
而且似乎不知道为什么。我在my settings.py中正确地指定了我的
TEMPLATE\u DIR
,并确保该文件存在于is所说的位置。我还研究了所有这些问题,其中人们有相同的问题,但没有一个解决了我的问题:

真正让我困惑的是,如果我检查BASE_DIR和TEMPLATE_DIR的值,它会给出:

/Users/user/Devspace/scren\u savers/the\u screen\u savers
/Users/user/Devspace/scren\u savers/the\u screen\u savers/templates

这正是我希望看到的。它似乎知道模板在哪里,但仍然看不到它们。任何帮助都将不胜感激

另外还有一个不太重要的问题:

我已经看到
BASE\u DIR+'/templates'
os.path.join(BASE\u DIR,“templates”)
被建议作为指定
TEMPLATE\u DIR
的正确方法。是其中一个比另一个好(如果是的话,为什么),还是这只是个人偏好的问题

以下是我试图加载的视图:

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')
这是我的设置文件:

# 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/'

您应该将file settings.py TEMPLATE\u DIR更改为TEMPLATE\u DIRS。

您应该将file settings.py TEMPLATE\u DIR更改为TEMPLATE\u DIRS