2017-09-22 5 views
1

/ app/index.htmlまたはindex.htmlにTemplateDoesNotExistというエラーがあります。 アプリ(子アプリ)がtestappと(親アプリ)であり、そしてアプリはindex.htmlにしている・urls.py・アプリのviews.py .urls.pyはtestappとのTemplateDoesNotExist at /何が間違っていますか?

from django.conf.urls import url 
    from . import views 


    urlpatterns = [ 
     url(r'^$', views.index, name='index'), 
    ] 
views.py of app is 
from django.shortcuts import render 


def index(request): 
    return render(request, 'app/index.html') 

urls.pyは

ですアプリでviews.pyの
from django.conf.urls import include, url 
from django.contrib import admin 
from app.views import index 

urlpatterns = [ 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'^$', index, name='index'), 
] 

レンダリングの引数は、「index.htmlを」に変更しましたが、同じエラーhappens.Whatは間違っている?(ディレクトリを記述する方法?) どうすればこの問題を解決する必要がありますか? トレースバックは、あなたの持っている、その後設定

INSTALLED_APPS = ['your_app_name'] 

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', 
       'django.template.context_processors.media' 
      ], 
     }, 
    }, 
] 

下記のおsettings.pyをチェック

Traceback: 

File "/Users/XXX/myenv/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner 
    41.    response = get_response(request) 

File "/Users/XXX/myenv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response 
    187.     response = self.process_exception_by_middleware(e, request) 

File "/Users/XXX/myenv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response 
    185.     response = wrapped_callback(request, *callback_args, **callback_kwargs) 

File "/Users/XXX/testapp/app/views.py" in index 
    5.  return render(request, 'index.html') 

File "/Users/XXX/myenv/lib/python3.5/site-packages/django/shortcuts.py" in render 
    30.  content = loader.render_to_string(template_name, context, request, using=using) 

File "/Users/XXX/myenv/lib/python3.5/site-packages/django/template/loader.py" in render_to_string 
    67.   template = get_template(template_name, using=using) 

File "/Users/XXX/myenv/lib/python3.5/site-packages/django/template/loader.py" in get_template 
    25.  raise TemplateDoesNotExist(template_name, chain=chain) 

Exception Type: TemplateDoesNotExist at/
Exception Value: index.html 

答えて

0

TEMPLATE_DIRS = (
    os.path.join(SETTINGS_PATH, 'templates'), 
) 

は、Djangoは、プロジェクトの下に、テンプレート/ディレクトリからのテンプレートを見てみましょうことを意味します。

OR

SETTINGS_PATHは、デフォルトで定義することはできません。その場合、あなたは(settings.pyで)それを定義したいと思うでしょう:

import os 

SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__)) 

そして、あなたはこの

アプリ/ index.htmlを

のように移動する場合テンプレートフォルダ内にアプリフォルダを作成する必要があります

お試しください

TEMPLATES = [ 
{ 
    'BACKEND': 'django.template.backends.django.DjangoTemplates', 
    'DIRS': ['/your/dir/here/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', 
     ], 
    }, 
}, 

] comments.Iウル

+0

thx ur comments.I ur codesを書きましたが、同じエラーが発生しました。他の問題はどう思いますか? – user8634222

+0

設定ファイルにTEMPLATE_LOADERSがありますか? –

+0

djangoのどのバージョンを使用しますか? –

0

あなたのテンプレートは(yourapp /テンプレート/ index.htmlに)にする必要がありますHI

語りますview.py

0設定ファイル内
+0

THXは、ウルのコードを書きましたが、同じエラーhappens.What uは、他の問題だと思いますか? – user8634222

+0

エラーを追加できます – Robert

+0

トレースバックを更新しました。 – user8634222

関連する問題