Django:TemplateDoesNotExist错误

时间:2018-06-21 14:31:46

标签: python django

我正在将模板链接到视图,但是遇到了这个问题。

我不知道问题出在哪里

这是回溯

Traceback:

File "/home/choco/.local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/home/choco/.local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "/home/choco/.local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/choco/python3/django/choco/blog/views.py" in post_list
  4.     return render(request, 'blog/post_list.html', {})

File "/home/choco/.local/lib/python3.6/site-packages/django/shortcuts.py" in render
  36.     content = loader.render_to_string(template_name, context, request, using=using)

File "/home/choco/.local/lib/python3.6/site-packages/django/template/loader.py" in render_to_string
  61.         template = get_template(template_name, using=using)

File "/home/choco/.local/lib/python3.6/site-packages/django/template/loader.py" in get_template
  19.     raise TemplateDoesNotExist(template_name, chain=chain)

Exception Type: TemplateDoesNotExist at /
Exception Value: blog/post_list.html

blog / blog / urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('', views.post_list, name = 'post_list'),
]

blog / mysite / urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('blog.urls')),
]

blog / blog / views.py

from django.shortcuts import render

def post_list(request):
    return render(request, 'blog/post_list.html', {})

blog / blog / blog / templates / blog / post_list.html

blog / mysite / settings.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',
            ],
        },
    },
]

1 个答案:

答案 0 :(得分:0)

检查项目目录的层次结构。应该是这样的:

myproject
-> mysite
  -> mysite
    - __init__.py
    - settings.py
  -> blog
    -> templates
    - urls.py
    - views.py