1

我有一个循环导入问题:

 File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 96, in load_app
    models = import_module('.models', app_name)

 File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)

  File "/Users/......../account/models.py", line 11, in <module>
    from account import model_managers as model_mgrs

  File "/Users/......../account/model_managers.py", line 6, in <module>
    from account import models as account_models
ImportError: cannot import name models

我按照这个人的建议只导入模块来处理循环导入:https ://stackoverflow.com/a/3956038/1724763

但我仍然有一个错误。现在怎么办?

更新

好的,我在 account/model_managers.py 中解决了这个问题:

import importlib
account_models = importlib.import_module('.models', 'account')

虽然它看起来很笨拙。不确定它是否是pythonic ...

4

0 回答 0