我正在构建 django 应用程序,但遇到了 som 导入问题。我的文件结构:
project/
my_app/
models/
__init__.py
Article.py
StockMovementProduct.py
tools/
__init__.py
Synchronizer.py
项目/my_app/models/_初始化_.py:
from Article import *
from StockMovementProduct import *
项目/my_app/models/Article.py:
from django.db import models
class Article(models.Model):
[...]
项目/my_app/models/StockMovementProduct.py:
from django.db import models
from my_app.tools import Synchronizer
class StockMovementProduct(models.Model):
def sync_articles(self):
sync = Synchronizer(self)
[...]
project/my_app/tools/_ init _.py为空
项目/my_app/tools/Synchronizer.py:
from my_app.models import Article
from my_app.models import StockMovementProduct
class Synchronizer():
[...]
当我运行我的代码时,会引发此错误:
File "/home/bux/Projets/project/my_app/models/__init__.py", line 7, in <module>
from StockMovementProduct import *
File "/home/bux/Projets/project/my_app/models/StockMovementProduct.py", line 5, in <module>
from my_app.tools import Synchronizer
File "/home/bux/Projets/project/my_app/tools/Synchronizer.py", line 2, in <module>
from my_app.models import StockMovementProduct
ImportError: cannot import name StockMovementProduct
我不明白为什么(在 Synchronizer.py 中)文章导入工作和StockMovementProduct导入不工作。
在 Synchronizer.py 我也尝试:
from my_app.models import Article
from ..models import StockMovementProduct
但没有成功。我在导入方法中缺少什么?