如何将模型从一个Django应用程序导入到另一个?

时间:2020-07-16 13:53:39

标签: python django django-models

我尝试使用以下方法将模型从一个应用程序导入到另一个应用程序:

from ..appName.models import className

from appName.models import className

但发生试图超出顶级程序包的相对导入错误。我的目的是创建一个学生管理系统。在一个应用程序中,我创建了模型,在另一个应用程序中,我尝试从该模型中检索数据,但没有成功。

├───Save_to_database
│   ├───HelpingClass
│   │   └───__pycache__
│   ├───migrations
│   │   └───__pycache__
│   └───__pycache__
├───Search
│   ├───migrations
│   │   └───__pycache__
│   └───__pycache__
├───StudentApp
│   └───__pycache__
└───templates

我想将模型从save_to_database导入到Search。

是的,我将应用程序添加到settings.py

请问我的英语

1 个答案:

答案 0 :(得分:0)

├───Save_to_database
│   ├───HelpingClass
│   │   └───__pycache__
│   ├───migrations
│   │   └───__pycache__
│   └───__pycache__
├───Search
│   ├───migrations
│   │   └───__pycache__
│   └───__pycache__
├───StudentApp
│   └───__pycache__
└───templates

我想将模型从save_to_database导入到Search。

是的,我将应用程序添加到settings.py