我有一个django应用程序叫做customer。在customer.models
我有一些模型类,其中之一是牙齿。我还在我的应用程序目录中创建了一个新的python文件,名为回调.py为某些信号存储一些回调函数。我要做的是
from customer.models import Tooth
def callback(sender, **kwargs)
#using Tooth here
就这样模型.py在
^{pr2}$但是当我尝试运行sqlall时,我得到了一个导入错误
from customer.models import Tooth
ImportError: cannot import name Tooth
其他的一切都正常。在
编辑:使用django1.6版本
这是循环导入。在
发生的情况如下:
customer.models
customer/models.py
的内容来计算模块的属性customers/models.py
进口customer/callbacks.py
customer/models.py
的执行,并开始执行customer/callbacks.py
callbacks.py
尝试导入正在导入的models.py
。Python阻止模块的双重导入并引发一个ImportError。在通常这种情况下设计很差。但有时(这似乎是你的情况)紧密耦合是必要的。解决这一问题的一种快速而肮脏的方法是延迟循环导入,在您的情况下:
在
models.py
中:在
^{pr2}$callbacks.py
中:相关问题 更多 >
编程相关推荐