Django模板查找不在应用程序中查找

时间:2016-04-05 01:51:38

标签: django django-templates

Uber simple app。我的views.py:

from django.http import HttpResponse
from django.shortcuts import render
from django.template import loader

def index(request):
    #return HttpResponse("Ready to turn some webpages into workflowies?")
    template = loader.get_template('web/index.html')

    return HttpResponse(template.render(context, request))

我正在尝试渲染我的第一个模板,我得到了

  在

TemplateDoesNotExist

Template-loader postmortem

Django tried loading these templates, in this order:

Using engine django:
django.template.loaders.app_directories.Loader: C:\utils\python\Python34\lib\site-packages\django\contrib\admin\templates\web\index.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\utils\python\Python34\lib\site-packages\django\contrib\auth\templates\web\index.html (Source does not exist)

为什么加载程序找不到/web/templates/index.html中的模板?

1 个答案:

答案 0 :(得分:1)

您将index.html放在/web/templates/web/index.html中。它会工作。在settings.py中,请将网络应用添加到

   INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'web',