位于/base/index.html的TemplateDoesNotExist [英] TemplateDoesNotExist at / base/index.html

查看:47
本文介绍了位于/base/index.html的TemplateDoesNotExist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Django,正在构建登录页面.我收到TemplateDoesNotExist错误,我想我知道原因,但不知道如何解决.我的 index.html coffeedapp/coffeedapp/templates/base/index.html 中但是,似乎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 有人可以告诉我为什么会这样吗?

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

我使用Django 1.8.1

I use Django 1.8.1.

我的代码在下面(对于settings.py,我仅显示添加或修改的代码):

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

views.py

views.py

来自django.shortcuts的

from django.shortcuts import render
from django.views.generic import TemplateView
class LandingView(TemplateView):
    template_name = 'base/index.html'

core/urls.py

core/urls.py

django.conf.urls中的

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

coffeedapp/urls.py

django.conf.urls中的

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

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'),
)

推荐答案

您正在使用哪个版本的Django?您是否已设置TEMPLATE_DIRS或DIRS来指示Django在哪里寻找模板?

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

发布您的settings.py,urls.py和views.py将有助于首先解决问题.

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.

从settings.py中删除TEMPLATE_DIRS

Remove TEMPLATE_DIRS from settings.py

添加标准Django 1.8.x模板设置

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',
            ],
        },
    },
]

检查更新注释.

这篇关于位于/base/index.html的TemplateDoesNotExist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆