2017-02-06 5 views
0

私のプロジェクトで/ home.htmlでTemplateDoesNotExistはDjangoは: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 

ある

] [私たちは私の現在のプロジェクトのために何をすべきか、この...

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     #'DIRS': [], 
     'DIRS': [ 
      os.path.join(BASE_DIR, 'lucifer/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', 

       # Enable {{ STATIC_URL }} and {{ MEDIA_URL }} 
       'django.template.context_processors.media', 
       'django.template.context_processors.static', 
      ], 
     }, 
    }, 
] 
+0

あなたは 'TEMPLATES' varを投稿できますか? – arcegk

+0

@arcegk um。申し訳ありませんが、私はあなたのコメントを理解できませんテンプレートとは何ですかvar?変数テンプレートコードの場合は、私の質問にこのコードを挿入します –

+0

@MinHan、TEMPLATES設定は設定ファイルのどこかにあるべきです。 MacまたはUnixの場合は、 'grep TEMPLATES'を実行するか、手動でファイルを調べてみてください。 – Tony

答えて

0

TEMPLATESを追加

0
'DIRS': [os.path.join(dirname(dirname(__file__)), '..')+'/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', 
      ], 
     }, 
    }, 
] 
0

この記事を試す:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [os.path.join(BASE_DIR, 'templates'), ], 
     'APP_DIRS': '', 
     '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', 
       'django.template.context_processors.media', 
       'django.template.context_processors.static', 
      ], 
      'loaders':[ 
       'django.template.loaders.filesystem.Loader', 
      ] 

     }, 

    }, 
] 
関連する問題