【发布时间】:2019-08-26 11:00:14
【问题描述】:
跟进 [https://realpython.com/location-based-app-with-geodjango-tutorial/] 并实施附近的商店应用程序。但是,即使文件存在于指定的文件夹中,也会在 / 处获取 TemplateDoesNotExist。
尝试过的解决方案:
在“商店”应用中创建子目录(模板)
在 settings.py 中更改了 DIRS
settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [''],
'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',
],
},
},
]
此外,模板事后说明:
模板加载器事后分析
Django 尝试按以下顺序加载这些模板:
使用引擎 django:
django.template.loaders.filesystem.Loader: /home/username/sampleShops/nearbyshops/nearbyshops/shops (Source does not exist)
django.template.loaders.app_directories.Loader: /home/username/.local/lib/python3.6/site-packages/django/contrib/admin/templates/nearbyshops/shops (Source does not exist)
django.template.loaders.app_directories.Loader: /home/username/.local/lib/python3.6/site-packages/django/contrib/auth/templates/nearbyshops/shops (Source does not exist)
django.template.loaders.app_directories.Loader: /home/username/.local/lib/python3.6/site-packages/django/contrib/gis/templates/nearbyshops/shops (Source does not exist)
` 此外,我不在虚拟环境中工作(如果这会有所不同,尽管它不应该)
【问题讨论】:
-
您的应用是否在 INSTALLED_APP 中包含模板?
-
是的,它在 INSTALLED_APPS 中。
标签: django view python-3.6