python - django 模板对大写或小写文件夹名称敏感
问题描述
在Ubuntu 18上,使用 Django 2.1.2,我从这个github克隆了一个 repo :在 learning_logs/templates/ 中有一件非常奇怪的事情,我必须为 index.html 创建“Learning_log”,为其他 html 创建“learning_logs” ,如果我只使用一个来放置所有文件,它就会出现 TemplateDoesNotExist。详情如下:
只使用“learning_logs”:
“TemplateDoesNotExist”错误(TemplateDoesNotExist at / Learning_logs/index.html)
只使用“Learnning_logs”:
“TemplateDoesNotExist”错误(TemplateDoesNotExist at /learning_logs/base.html)
好像同时需要“ learning_logs ”“Learning_logs”,
我该如何解决?
谢谢!!
解决方案
这是因为在设置中没有提到调用模板时在哪里查看。
将此添加到模板标签下的设置中,或根据您自己的目的进行修改:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'),'./learning_logs/templates','./Learning_logs/templates'],
'APP_DIRS': True,
...
},
]
注意:如果模板文件夹与设置位于同一目录中,则添加os.path.join(BASE_DIR, 'templates'),]'
就足够了,否则应添加文件夹的位置,例如,,'./Learning_logs/templates'
另外,看看这个。
在您看来,尝试删除learning_logs/这个相对而言:像这样:
return render(request, 'index.html', context)
推荐阅读
- reactjs - 在反应中使用 useParams 挂钩
- sql - 如何使用 JPA spring boot 加入
- c# - SignalR Core 抛出已处理的异常
- indexeddb - 为什么 IndexedDB 挂起?
- java - 单元测试:一次测试中有 2 个场景?
- symfony - API PLATFORM ApiTestCase 身份验证发送意外响应
- r - R中y轴的不同间隔
- python - TensorFlow 1.x 上用于优化的 TFLiteConverter 参数
- python - 如何仅获取父目录的名称,而不是完整路径?
- debugging - 如何在使用 Segger J-link pro 和 Stm32cubeIDE 进行调试期间暂停看门狗计数器