No module named 'django.templates'起因和解决

当我跟着django官网上的教程写到template模板这一部分的时候,出现了上述问题

No module named 'django.templates'

这我是懵逼的,我代码里压根没直接调用django.templates,而是调用了django.shortcuts.render,由它间接调用了前者,为什么内部django的内部逻辑会出错呢?

当然还是自己错了……

具StackOverFlow上HoangYell大佬的解释https://stackoverflow.com/questions/30260055/no-module-named-django-templates:

This error always happens to the newbies who use Pycharm IDE for the first time. You renamed “templates” directory to another name by refactoring. When you do this act, it’s also renamed some strings in “settings.py”. So right click your “setting.py” -> LocalHistory -> ShowHistory then backup you “setting.py”.

这个问题经常出现在第一次使用Pycharm IDE的菜鸟身上。你把某个文件重命名为“templates”的同时,影响了settings.py文件,使得其中的某些东西也发生了变更。所以右击settings.py->LocalHistory -> ShowHistory 然后还原你的setting.py

然后我就恍然大悟了,之前确实因为起错文件夹名,把“template”重命名到了“templates”,然后又马马虎虎点了个确定,所以settings.py里的“template”也变成“templates”了,所以就出现了找不到django.templates的问题了。

解决方法当然就是去settings.py里边把误伤的部分该回去啦。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孔天逸

没有钱用,只能写写博客这样子~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值