在PyCharm2017中同目录下import其他模块,会出现No model named ...的报错,但实际可以运行

这是因为PyCharm不会将当前文件目录自动加入source_path。

在当前目录右键make_directory as-->Sources Root

 

当你django结构发生变化 需要将你的app添加的路径列表里:

1 import os
2 import sys

4 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
5 sys.path.insert(0,os.path.join(BASE_DIR,'apps'))

 

在PyCharm2017中同目录下import其他模块,会出现No model named ...的报错,但实际可以运行

这是因为PyCharm不会将当前文件目录自动加入source_path。

在当前目录右键make_directory as-->Sources Root

 

当你django结构发生变化 需要将你的app添加的路径列表里:

1 import os
2 import sys

4 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
5 sys.path.insert(0,os.path.join(BASE_DIR,'apps'))

 

相关文章: