python django巨坑之templates模板django.template.exceptions.TemplateDoesNotExist

最近在自学django,到了templates配置显示静态文件,一直卡在这里报错了,明明是抄别人竟然还说找不到模板,脑袋都大了,查询一圈,setting也配置了依然不行,痛苦

记录一下我的解决方案:【因为大家基本都是新手借鉴的代码,所以基本上其他地方不会有问题,维度下面这个,可能跟视频有一些不一样】

找到setting文件 ,注意仔细观察你的templates的模板文件路径,此时可以输出一下BASE_DIR,下面控制台可以查看到。注意看我的,仅仅输出了F:\python_project\django\firstproject,然而我右侧却还有一层firstproject!!所以这里一直找不到templates

 于是乎,下面的图片再拼接路径,不能只写一个templates而应该写成我缺少的路径‘firstproject/templates’而不是'templates',此时你也可以直接输出一下,观察一下与左边目录templates对的上不。

print(os.path.join(BASE_DIR,'firstproject/templates'))

猜你喜欢

转载自blog.csdn.net/qq_43644046/article/details/130482273