我正在学习 Django 并正在构建一个登陆页面。
我收到 TemplateDoesNotExist 错误,我想我知道原因,但我不知道如何解决此问题。
我的index.html
is in coffeedapp/coffeedapp/templates/base/index.html
然而 Django 似乎试图从以下位置加载文件
coffeedapp/lib/python2.7/site-packages/django/contrib/admin/templates/base/index.html
有人能告诉我为什么会发生这种情况吗?
我使用 Django 1.8.1。
我的代码如下(对于settings.py,我只显示我添加/修改的代码):
views.py
from django.shortcuts import render
from django.views.generic import TemplateView
class LandingView(TemplateView):
template_name = 'base/index.html'
核心/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')),
)
设置.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'),
)