如何修复 Windows10 上的 TemplateDoesNotExist 错误?
How to fix TemplateDoesNotExist Error on Windows10?
我一直在学习 [编写您的第一个 Django 应用程序][1]
教程
在第 3 部分中,我尝试使用模板。我在 Windows10.
上使用 Python 3.1、Django 3.2
下面是我得到的错误:
Django tried loading these templates, in this order:
Using engine django:
- django.template.loaders.app_directories.Loader:
C:\Users\KKK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\admin\templates\polls\index.html (Source does not exist)
- django.template.loaders.app_directories.Loader:
C:\Users\KKK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\auth\templates\polls\index.html (Source does not exist)
下面是我的文件结构:
mysite
+-- mysite
| +--settings.py
| +--other files
+-- polls
| +--templates
| | +--polls
| | | +--index.html
| +--views.py
| +--other files
+-- db.sqlite3
+-- manage.py`
我在 INSTALLED_APPS 设置中添加了对投票配置 class 的引用。
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
如有任何帮助,我们将不胜感激。
您可能需要指示 django 在哪里可以找到您的模板,将其(第 60 行附近的某处)放在 settings.py
中
# settings.py
TEMPLATES = [
'DIRS': [os.path.join(BASE_DIR, 'templates')],
]
我一直在学习 [编写您的第一个 Django 应用程序][1]
教程在第 3 部分中,我尝试使用模板。我在 Windows10.
上使用 Python 3.1、Django 3.2下面是我得到的错误:
Django tried loading these templates, in this order:
Using engine django:
- django.template.loaders.app_directories.Loader:
C:\Users\KKK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\admin\templates\polls\index.html (Source does not exist)
- django.template.loaders.app_directories.Loader:
C:\Users\KKK\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\auth\templates\polls\index.html (Source does not exist)
下面是我的文件结构:
mysite
+-- mysite
| +--settings.py
| +--other files
+-- polls
| +--templates
| | +--polls
| | | +--index.html
| +--views.py
| +--other files
+-- db.sqlite3
+-- manage.py`
我在 INSTALLED_APPS 设置中添加了对投票配置 class 的引用。
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
如有任何帮助,我们将不胜感激。
您可能需要指示 django 在哪里可以找到您的模板,将其(第 60 行附近的某处)放在 settings.py
中# settings.py
TEMPLATES = [
'DIRS': [os.path.join(BASE_DIR, 'templates')],
]