Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何解决django错误:raise TEMPLATEDOESNOTEXTIST(';,';。join(模板名称列表),chain=chain)_Python_Django_Django Urls_Django Class Based Views_Django 3.0 - Fatal编程技术网

Python 如何解决django错误:raise TEMPLATEDOESNOTEXTIST(';,';。join(模板名称列表),chain=chain)

Python 如何解决django错误:raise TEMPLATEDOESNOTEXTIST(';,';。join(模板名称列表),chain=chain),python,django,django-urls,django-class-based-views,django-3.0,Python,Django,Django Urls,Django Class Based Views,Django 3.0,我正在使用Django 3+ 我试图在我的页面上呈现博客模板,但收到错误: Internal Server Error: /postsblog Traceback (most recent call last): File "D:\Projetos Dev\gpprofessional\.venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_respons

我正在使用Django 3+

我试图在我的页面上呈现博客模板,但收到错误:

Internal Server Error: /postsblog
Traceback (most recent call last):
  File "D:\Projetos Dev\gpprofessional\.venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "D:\Projetos Dev\gpprofessional\.venv\lib\site-packages\django\core\handlers\base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "D:\Projetos Dev\gpprofessional\.venv\lib\site-packages\django\core\handlers\base.py", line 143, in _get_response
    response = response.render()
  File "D:\Projetos Dev\gpprofessional\.venv\lib\site-packages\django\template\response.py", line 105, in render
    self.content = self.rendered_content
  File "D:\Projetos Dev\gpprofessional\.venv\lib\site-packages\django\template\response.py", line 81, in rendered_content
    template = self.resolve_template(self.template_name)
  File "D:\Projetos Dev\gpprofessional\.venv\lib\site-packages\django\template\response.py", line 63, in resolve_template
    return select_template(template, using=self.using)
  File "D:\Projetos Dev\gpprofessional\.venv\lib\site-packages\django\template\loader.py", line 47, in select_template
    raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: posts/blog.html, posts/post_list.html
[13/May/2020 22:57:09] "GET /postsblog HTTP/1.1" 500 93437
尝试访问博客URL时发生此错误

我的项目中有一些应用程序,如应用程序库、应用程序帖子、应用程序博客和应用程序分类

我要创建的目录文件类似于图像:

应用程序库中的我的文件: URL

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home, name='home'),
    path('posts', include('posts.urls')),
    path('summernote/', include('django_summernote.urls'))
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView


def home(request):
    return render(request, 'home.html')
from django.urls import path
from . import views


urlpatterns = [
    path('blog', views.PostIndex.as_view(), name='post_blog'),
    path('categoria/<str:categoria>', views.PostCategoria.as_view(), name='post_categoria'),
    path('busca/', views.PostBusca.as_view(), name='post_busca'),
    path('post/<int:pk>', views.PostDetalhes.as_view(), name='post_detalhes'),
]
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView
from .models import Post


class PostIndex(ListView):
    model = Post
    template_name = 'posts/blog.html'


class PostBusca(PostIndex):
    pass


class PostCategoria(PostIndex):
    pass


class PostDetalhes(UpdateView):
    pass
视图

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home, name='home'),
    path('posts', include('posts.urls')),
    path('summernote/', include('django_summernote.urls'))
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView


def home(request):
    return render(request, 'home.html')
from django.urls import path
from . import views


urlpatterns = [
    path('blog', views.PostIndex.as_view(), name='post_blog'),
    path('categoria/<str:categoria>', views.PostCategoria.as_view(), name='post_categoria'),
    path('busca/', views.PostBusca.as_view(), name='post_busca'),
    path('post/<int:pk>', views.PostDetalhes.as_view(), name='post_detalhes'),
]
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView
from .models import Post


class PostIndex(ListView):
    model = Post
    template_name = 'posts/blog.html'


class PostBusca(PostIndex):
    pass


class PostCategoria(PostIndex):
    pass


class PostDetalhes(UpdateView):
    pass
应用程序帖子中的我的文件: URL

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home, name='home'),
    path('posts', include('posts.urls')),
    path('summernote/', include('django_summernote.urls'))
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView


def home(request):
    return render(request, 'home.html')
from django.urls import path
from . import views


urlpatterns = [
    path('blog', views.PostIndex.as_view(), name='post_blog'),
    path('categoria/<str:categoria>', views.PostCategoria.as_view(), name='post_categoria'),
    path('busca/', views.PostBusca.as_view(), name='post_busca'),
    path('post/<int:pk>', views.PostDetalhes.as_view(), name='post_detalhes'),
]
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView
from .models import Post


class PostIndex(ListView):
    model = Post
    template_name = 'posts/blog.html'


class PostBusca(PostIndex):
    pass


class PostCategoria(PostIndex):
    pass


class PostDetalhes(UpdateView):
    pass
我的文件设置在模板已安装的应用程序配置中看起来像:

模板

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',
            ],
        },
    },
]
INSTALLED_APPS = [
    'posts',
    'categorias',
    'comentarios',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'collectfast',
    'django.contrib.staticfiles',
    'base',
    'blog',
]
ISTALLED\u应用程序

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',
            ],
        },
    },
]
INSTALLED_APPS = [
    'posts',
    'categorias',
    'comentarios',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'collectfast',
    'django.contrib.staticfiles',
    'base',
    'blog',
]

我试图使用所有模板的唯一文件夹,但出现了错误。我认为错误应该在URL基文件中,但我不知道如何解决它。我在谷歌上做了一些搜索,但没有成功…

考虑到模板加载器在所有应用程序中都通过模板,所以在你的情况下,你不需要在模板名称前面添加应用程序

template_name = 'blog.html'

显示您的设置模板变量和已安装的\u APPSI编辑了我的帖子添加模板和已安装的\u apps您只发布了模板:)已调整,抱歉!如果我改变了,新的错误就会发生…````从exc django.template.exceptions.TemplateDoesNotExist:base/base.html``您是否更改了有关此项目模板结构的某些内容,因为您可能会注意到,如果删除base,错误与其他模板相同/它将起作用(或导致另一个错误)。您可以添加额外的顶级目录,并将其称为应用程序名,以避免重命名所有TemplatesOrry,但我不明白。。。仅创建一个新目录并将应用程序库放在其中以解决问题?不,创建类似以下base/templates/base/的文件夹结构,并将所有直接位于base/templates中的内容放在其中(您也可以对其他应用程序执行类似操作)谢谢我的朋友!发生错误是因为包含有错误。调整后,模板被渲染!include标记上的blog.html文件中出现错误。