如何解决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']
注意:我已经浏览了这些链接,但对我没有帮助,我已经检查过这些链接。我添加了页面应用程序并且它工作正常,但是当我尝试添加列表应用程序时它不起作用。
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',]
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),]
上市申请:
在列表中配置 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')
在模板文件夹内
解决方法
您使用大写 L 创建了列表。但是您在 views.py 中使用了小 l。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。