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

 成都迅捷代驾 发布于 2022-11-08 10:54

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。

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

    2022-11-12 01:44 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有