Django 3.2.2 上的 TemplateDoesNotExist

问题描述

我在尝试添加新应用程序时收到以下错误

TemplateDoesNotExist at /listings/
listings/listings.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/listings/
Django Version: 3.2.2
Exception Type: TemplateDoesNotExist
Exception Value:    
listings/listings.html
Exception Location: /home/brup/Desktop/Python/Django/FullWebApplication/btre_project/venv/lib/python3.6/site-packages/django/template/loader.py,line 19,in get_template
Python Executable:  /home/brup/Desktop/Python/Django/FullWebApplication/btre_project/venv/bin/python
Python Version: 3.6.9
Python Path:    
['/home/brup/Desktop/Python/Django/FullWebApplication/btre_project','/usr/lib/python36.zip','/usr/lib/python3.6','/usr/lib/python3.6/lib-dynload','/home/brup/Desktop/Python/Django/FullWebApplication/btre_project/venv/lib/python3.6/site-packages']

注意:我已经浏览了这些链接,但对我没有帮助,我已经检查过这些链接。我添加页面应用程序并且它工作正常,但是当我尝试添加列表应用程序时它不起作用。

Solution1 Solution2 Solution3

    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 = [
        'pages.apps.PagesConfig','listings.apps.ListingsConfig','realtors.apps.RealtorsConfig','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',]

在 urls.py 中,我添加了以下内容

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

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

上市申请:

enter image description here

在列表中配置 urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('',views.index,name='listings'),path('<int:listing_id>',views.listing,name='listing'),path('search',views.search,name='search'),]

配置视图

from django.shortcuts import render

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

def listing(request,listing_id):
    return render(request,'listings/listing.html')

def search(request):
  return render(request,'listings/search.html')

在模板文件夹内

enter image description here

解决方法

您使用大写 L 创建了列表。但是您在 views.py 中使用了小 l。