【问题标题】:How to import models frome one Django app to another?如何将模型从一个 Django 应用程序导入到另一个应用程序?
【发布时间】:2020-07-16 13:53:39
【问题描述】:

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

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 导入到搜索中。

是的,我在 settings.py 中添加了应用程序

请原谅我的英语

【问题讨论】:

标签: python django django-models


【解决方案1】:
├───Save_to_database
│   ├───HelpingClass
│   │   └───__pycache__
│   ├───migrations
│   │   └───__pycache__
│   └───__pycache__
├───Search
│   ├───migrations
│   │   └───__pycache__
│   └───__pycache__
├───StudentApp
│   └───__pycache__
└───templates

我想将模型从 save_to_database 导入到搜索中。

是的,我在 settings.py 中添加了应用程序

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 2011-12-22
    • 2019-05-17
    • 1970-01-01
    相关资源
    最近更新 更多