如何解决Django 4.2中运行服务器时出现的'TemplateDoesNotExist'错误?

fdbelqdn  于 2023-05-23  发布在  Go
关注(0)|答案(1)|浏览(166)
TemplateDoesNotExist at /
home.html
Request Method: GET
Request URL:    http://127.0.0.1:5555/
Django Version: 4.2.1
Exception Type: TemplateDoesNotExist
Exception Value:    
home.html
Exception Location: C:\Users\soumy\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\template\loader.py, line 19, in get_template
Raised during:  geekshows.views.home
Python Executable:  C:\Users\soumy\AppData\Local\Programs\Python\Python311\python.exe
Python Version: 3.11.3
Python Path:    
['F:\\Django\\geekshows',
 'C:\\Users\\soumy\\AppData\\Local\\Programs\\Python\\Python311\\python311.zip',
 'C:\\Users\\soumy\\AppData\\Local\\Programs\\Python\\Python311\\DLLs',
 'C:\\Users\\soumy\\AppData\\Local\\Programs\\Python\\Python311\\Lib',
 'C:\\Users\\soumy\\AppData\\Local\\Programs\\Python\\Python311',
 'C:\\Users\\soumy\\AppData\\Roaming\\Python\\Python311\\site-packages',
 'C:\\Users\\soumy\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages']
Server time:    Mon, 22 May 2023 13:56:05 +0000

Template-loader postmortem
Django tried loading these templates, in this order:

Using engine django:

django.template.loaders.filesystem.Loader: F:\Django\geekshows\templates\home.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\soumy\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\admin\templates\home.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\soumy\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\templates\home.html (Source does not exist)
django.template.loaders.app_directories.Loader: F:\Django\geekshows\course\templates\home.html (Source does not exist)
django.template.loaders.app_directories.Loader: F:\Django\geekshows\fees\templates\home.html (Source does not exist)

当我运行服务器时,这个错误正在发生。我用的是Django 4.2,怎么用呢?

hpcdzsge

hpcdzsge1#

你似乎有一个视图home,呈现home.html,但home.html无法找到

Raised during:  geekshows.views.home
...
django.template.loaders.filesystem.Loader: F:\Django\geekshows\templates\home.html (Source does not exist)

请注意,你似乎有一个非标准的结构,你的应用程序作为一个视图文件应该在一个应用程序(如.../geekshows/main/views.py),但你似乎是在项目根文件夹geekshows。
标准结构:

geekshows/                      # project root
   main/                        # app main (or another name)
      templates/
          main/
             home.html
      models.py
      views.py
      ...
   course/                      # app course
   fees/                        # app fees
   geekshows/                   # folder with same name as project -> django entry point for requests
      urls.py
      wsgi.py
      settings.py
   manage.py

请发布视图并显示放置home.html的文件夹结构以进一步回答您的问题

相关问题