Django:TemplateDoesNotExist at/home.html 在我的项目中

标签 django django-templates

我不明白为什么 django 不能搜索“home.html”

我的项目名称是 lucifer
这是我的项目树

│   ├── lucifer
│   │   ├── __init__.py
│   │   ├── settings
│   │   │   ├── __init__.py
│   │   │   ├── development.py
│   │   │   ├── partials
│   │   │   │   ├── __init__.py
│   │   │   │   ├── base.py
│   │   │   │   ├── database.py
│   │   │   │   └── static.py
│   │   │   └── production.py
│   │   ├── templates
│   │   │   ├── base.html
│   │   │   ├── home.html
│   │   │   └── partials
│   │   │       ├── footer.html
│   │   │       └── header.html
│   │   ├── urls.py
│   │   ├── views
│   │   │   ├── __init__.py
│   │   │   └── home.py

和我的 home.html
{% extends 'base.html' %}

{% block title %}
Home
{% endblock %}

header.html
<p>it is header</p>

footer.html
<p>it is footer</p>

base.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>루시퍼 |{% block title %}{% endblock %}</title>
</head>
<body>

    {% include 'partials/header.html' %}

    {% block content %}
    {% endblock %}

    {% include 'partials/footer.html' %}

</body>
</html>

home.py
from django.views.generic import TemplateView


class Home(TemplateView):
    template_name = 'home.html'

urls.py
from django.conf.urls import url
from django.contrib import admin

from .views import *

urlpatterns = [
    url(r'^admin/', admin.site.urls),
url(r'$^', Home.as_view(), name='home'),
]

我觉得没有问题。。

但错误是
Django version 1.9.7, using settings 'lucifer.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Internal Server Error: /
Traceback (most recent call last):
  File "/Users/hanminsoo/.pyenv/versions/lucifer/lib/python3.4/site-packages/django/core/handlers/base.py", line 174, in get_response
response = self.process_exception_by_middleware(e, request)
  File "/Users/hanminsoo/.pyenv/versions/lucifer/lib/python3.4/site-packages/django/core/handlers/base.py", line 172, in get_response
response = response.render()
  File "/Users/hanminsoo/.pyenv/versions/lucifer/lib/python3.4/site-packages/django/template/response.py", line 160, in render
self.content = self.rendered_content
  File "/Users/hanminsoo/.pyenv/versions/lucifer/lib/python3.4/site-packages/django/template/response.py", line 135, in rendered_content
template = self._resolve_template(self.template_name)
  File "/Users/hanminsoo/.pyenv/versions/lucifer/lib/python3.4/site-packages/django/template/response.py", line 90, in _resolve_template
new_template = self.resolve_template(template)
  File "/Users/hanminsoo/.pyenv/versions/lucifer/lib/python3.4/site-packages/django/template/response.py", line 80, in resolve_template
return select_template(template, using=self.using)
  File "/Users/hanminsoo/.pyenv/versions/lucifer/lib/python3.4/site-packages/django/template/loader.py", line 74, in select_template
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: home.html
[06/Feb/2017 07:40:34] "GET / HTTP/1.1" 500 81753

请告诉我一些建议谢谢

地址 TEMPLATES 在 settings.partials.base.py
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

最佳答案

一定要放lucifer在您的 settings.py 内的 INSTALLED_APPSAPPS_DIR=True会告诉 Django look inside your installed apps .

关于Django:TemplateDoesNotExist at/home.html 在我的项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42062630/

相关文章:

Django Postgres 不区分大小写的文本字段和 citext

python - 基于 Django 类的 DetailView/ListView ajax 装饰器?

python - 如何在 Django 模板中的 {% %} 之间使用变量

django - 如何同时使用 safe 和 truncatechars 方法?

python - &lt;script&gt; 与包含在 Django 模板中的比较

Django 模板 : Comparing current url with {% url xyz %}

python - 一种保存 Django View 生成的 HTML 的方法?

django - 主管、 celery 、Virtualenvwrapper、Django : Could not import django settings even when pythonpath added to environment

django - 对于 django 管理员,如何向 User 模型添加字段并使其在管理员中可编辑?

python - Django:为每个实例注册模板过滤器/标签