求分析django工程目录里找不到导入模块原因,django模块,I generate a


I generate a django project and its directory structure is like the following:
我创建了一个django工程,目录树如下:

-myproject    --__init__.py    --settings.py    --rooturls.py    --dbUtils.py    --app1        ---__init__.py        ---views.py        ---urls.py    --app2        ---__init__.py        ---views.py        ---urls.py

I want to import dbUtils in my apps , so I configure in my settings.py:
我要导入 dbUtils,所以配置 settings.py:

PROJECT_ROOT = os.path.dirname(__file__)sys.path.insert(0, PROJECT_ROOT)

However, the program still can't find the moudle.
但是工程里还是找不到这个moudle。

在import dbUtils的文件中把sys.path 打印出来
看下全局搜索路径中是否包含dbUtils所在目录
酱紫就一目了然了

编橙之家文章,

评论关闭