2016-12-08 11 views
0

私のdjangoプロジェクトのホームページを作成しようとしています。私はこのエラーを得続ける:/エラー例外at-loader.py行にテンプレートが存在しません43

TemplateDoesNotExist at/
home.html 
Request Method: GET 
Request URL: http://xtradev.local/ 
Django Version: 1.9 
Exception Type: TemplateDoesNotExist 
Exception Value:  
home.html 
Exception Location: /home/epic/EPIC/venv/lib/python2.7/site-packages/django/template/loader.py in get_template, line 43 
Python Executable: /usr/bin/python 
Python Version: 2.7.9 
Python Path:  
['/home/epic/EPIC/EPIC-PROJECT/EPIC-Django/EPIC_AR', 
'/home/epic/EPIC/venv/lib/python2.7/site-packages', 
'/usr/lib/python2.7', 
'/usr/lib/python2.7/plat-x86_64-linux-gnu', 
'/usr/lib/python2.7/lib-tk', 
'/usr/lib/python2.7/lib-old', 
'/usr/lib/python2.7/lib-dynload', 
'/usr/local/lib/python2.7/dist-packages', 
'/usr/lib/python2.7/dist-packages', 
'/usr/lib/python2.7/dist-packages/PILcompat', 
'/usr/lib/python2.7/dist-packages/gst-0.10', 
'/usr/lib/python2.7/dist-packages/gtk-2.0', 
'/usr/lib/pymodules/python2.7'] 
Server time: Thu, 8 Dec 2016 14:04:41 +0000 

私のsettings.pyは、次のようになります。

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

] [マイテンプレート]フォルダは、私のプロジェクトのフォルダにあるとhome.htmlが含まれ

これはloader.pyのコードです(ただし、何をしているか正確に要求しているわけではありません):

def get_template(template_name, dirs=_dirs_undefined, using=None): 
""" 
Loads and returns a template for the given name. 

Raises TemplateDoesNotExist if no such template exists. 
""" 
chain = [] 
engines = _engine_list(using) 
for engine in engines: 
    try: 
     # This is required for deprecating the dirs argument. Simply 
     # return engine.get_template(template_name) in Django 1.10. 
     if isinstance(engine, DjangoTemplates): 
      return engine.get_template(template_name, dirs) 
     elif dirs is not _dirs_undefined: 
      warnings.warn(
       "Skipping template backend %s because its get_template " 
       "method doesn't support the dirs argument." % engine.name, 
       stacklevel=2) 
     else: 
      return engine.get_template(template_name) 
    except TemplateDoesNotExist as e: 
     chain.append(e) 

raise TemplateDoesNotExist(template_name, chain=chain) 

すべてが正しいと思われますが、私は何が見落としているのか分かりません。何か案は?

UPDATE: VIEWS.PY

from django.contrib.auth.models import User, Group 
from django.shortcuts import render, HttpResponse 
from rest_framework import filters 
from rest_framework import viewsets 

from serializers import UserSerializer, GroupSerializer 

def home(request): 
    return render(request, ('home.html')) 

class UserViewSet(viewsets.ModelViewSet): 
    queryset = User.objects.all() 
    serializer_class = UserSerializer 

URLS.PY

admin.site.site_header = 'EPIC.AR Administration' 

urlpatterns = [ 
    url(r'^$', 'EPIC_AR.views.home', name='Home'), 
    url(r'^admin/', admin.site.urls), 
    url(r'^api/1.0/', include(router.urls)), 
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), 

] 


Template-loader postmortem 

Django tried loading these templates, in this order: 

Using engine django: 
django.template.loaders.filesystem.Loader: /home/epic/EPIC/EPIC-PROJECT/EPIC-Django/EPIC_AR/templates/home.html (Source does not exist) 
django.template.loaders.app_directories.Loader: /home/epic/EPIC/venv/lib/python2.7/site-packages/suit/templates/home.html (Source does not exist) 
django.template.loaders.app_directories.Loader: /home/epic/EPIC/venv/lib/python2.7/site-packages/django/contrib/admin/templates/home.html (Source does not exist) 
django.template.loaders.app_directories.Loader: /home/epic/EPIC/venv/lib/python2.7/site-packages/django/contrib/auth/templates/home.html (Source does not exist) 
django.template.loaders.app_directories.Loader: /home/epic/EPIC/venv/lib/python2.7/site-packages/rest_framework/templates/home.html (Source does not exist) 
django.template.loaders.app_directories.Loader: /home/epic/EPIC/venv/lib/python2.7/site-packages/crispy_forms/templates/home.html (Source does not exist) 
django.template.loaders.app_directories.Loader: /home/epic/EPIC/EPIC-PROJECT/EPIC-Django/EPIC_AR/home/templates/home.html (Source does not exist) 

enter image description here

+0

このエラーは、あなたのプロジェクトの全面に渡っているのですか? 1つのアプリケーションだけの場合は、このアプリケーションのビューを表示 –

+0

さらにもう1つの質問、 'home.html'はどこに存在しますか? –

+0

私は自分のプロジェクトを推測します - 私はホームページとして働くことを試みている1つのテンプレートしか持っていません。私は他の人がいません。私はアプリに入れてみましたが、どちらもうまくいきません。 home.htmlは、アプリケーションレベルのメインプロジェクトフォルダにあります。アプリ内ではなく、settings.pyと同じフォルダにはありません(以前はそのレベルでしたが)。別のものを試してみました。 – Nicoale

答えて

1

のルートにhome.htmlを移動します物事が示唆された - 私が推測する物事の正しい順序を得ることの問題。

私はhome.htmlが置かれたディレクトリを追加しました:(views.pyで)

def home(request): 
return render(request, 'epicar/home.html') 

は、それから私は、BACKメインプロジェクトディレクトリにテンプレートフォルダを移動:

enter image description here

sudo service apache2 restart 

とwala!

enter image description here

エラーなし。:)

2

通常、私はアプリを追加するために忘れてしまった、このエラーが出るINSTALLED_APPS設定。

デフォルトローダがTEMPLATES['DIRS']で検索し、自分の視野や設定ファイルによるとINSTALLED_APPS

+0

すべてのアプリはsettings.pyにインストールされています。私のテンプレートフォルダはメインのプロジェクトフォルダにあります。私はそれをメインのものに入れて、レベルアップして助けてくれるかどうか確認しました。したがって、現在、プロジェクト内のすべてのアプリと同じレベルにあります。 – Nicoale

1

に指定されている各アプリのルートにテンプレートフォルダ、home.htmltemplatesフォルダ内にある必要があります。

soから、ビューにhome.htmlのパスを変更します。これは、の組み合わせだった

def home(request): 
    return render(request, ('home.html')) 

def home(request): 
    return render(request, ('pathtoapp/home.html')) 

またはtemplates

+0

Nope。ちょうどそれを試した。 TemplateDoesNotExist/ EPIC_AR /テンプレート/ epicar/home.html リクエストメソッドで:\t リクエストURLをGET:\tます。http://xtradev.local/ Djangoのバージョン:\t 1.9除いて同じエラーが、今では、ファイルのパスを示しています 例外タイプ:\t TemplateDoesNotExist 例外値:\t /EPIC-Django/EPIC_AR/templates/epicar/home.html 例外場所:\t /home/epic/EPIC/venv/lib/python2.7/site-packages/ django/template/loader.py in get_template、43行 – Nicoale

+0

あなたの質問に答えるのは難しいです。私はあなたのpの完全な構造を見ませんそれと一緒にフォルダ名を付ける –

関連する問題