当我跟着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
里边把误伤的部分该回去啦。