简体   繁体   English

Django:没有名为http_utils的模块

[英]Django: no module named http_utils

I created a new utils package and an http_utils file with some decorators and HTTP utility functions in there. 我创建了一个新的utils包和一个http_utils文件,其中带有一些装饰器和HTTP实用程序功能。 I imported them wherever I am using them and the IDE reports no errors, and I also added the utils module to the INSTALLED_APPS list. 我在使用它们的任何地方都导入了它们,并且IDE不报告任何错误,并且还将utils模块添加到INSTALLED_APPS列表中。

However, when launching the server I am getting an import error: 但是,启动服务器时出现导入错误:

ImportError: No module named http_utils ImportError:没有名为http_utils的模块

What am I missing? 我想念什么? What else do I need to do to register a new module? 注册新模块还需要做什么?

Make sure the package is correct (Include init .py file). 确保软件包正确(包括init .py文件)。

Make sure there are no other utils files in the same directory level. 确保在同一目录级别没有其他utils文件。 That is if you are importing from utils import http_utils from views.py, there should not be a utils.py in the same folder. 就是说,如果您是从utils导入,则是从views.py导入http_utils,则同一文件夹中不应有utils.py。 Conflict occurs because of that. 因此发生冲突。

You dont have to include the folder in the INSTALLED_APP settings. 您不必将文件夹包括在INSTALLED_APP设置中。 Because the utils folder is a package and should be available for importing 因为utils文件夹是一个软件包,应该可以导入

正如上面盯着由Arundas,因为是我建议重命名模块的东西,如utils.py文件utilities ,并确保你有在该目录中的__init__.py文件。

from utilities.http_utils import class_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM