Django 错误 - 导入错误:无法从“first_project”导入名称“first_app”

时间:2021-05-22 09:59:11

标签: python python-3.x django django-models django-forms

我是 Django 的新手,刚开始使用新项目。

我在尝试传入应用程序 URL 时遇到了这个问题。

导入错误:无法从“first_project”导入名称“first_app” (E:\Project\DjangoProject\first_project\first_project_init_.py)

view.py inside the first_app

urls.py inside the first_app

urls.py inside the first_project

1 个答案:

答案 0 :(得分:0)

尝试在 settings.py 中设置路径,如下所示:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, BASE_DIR)
sys.path.insert(0, os.path.join(BASE_DIR, 'backend/apps'))
sys.path.insert(0, os.path.join(BASE_DIR, 'backend/extra_apps'))
相关问题