首页 > 开发 > Python > 正文

django工程目录和导入规则的错误

2017-09-06 19:39:08  来源:网友分享

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所在目录
酱紫就一目了然了