简体   繁体   English

无法导入 '<app_name> '. 检查'<config> ' 是正确的</config></app_name>

[英]Cannot import '<app_name>'. Check that '<Config>' is correct

在此处输入图像描述

Given is my folder structure.给出的是我的文件夹结构。

In 'urls.py' of project-在项目的“urls.py”中-

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('apps.job_main.urls')),
]

In settings.py-在 settings.py-

INSTALLED_APPS = [
    'django.contrib.admin',
    .
    .
    'apps.job_main'
]

Complete error pastebin link完整的错误 pastebin 链接

In apps/job_main/apps.py-在 apps/job_main/apps.py-

from django.apps import AppConfig

class JobMainConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'job_main'

Is my import correct or any suggestions would be helpful?我的导入是否正确或有任何建议会有所帮助?

Django Version=3.2.4 Django 版本=3.2.4

It seems you have a sub-app named job_main .您似乎有一个名为job_main子应用程序 The problem here is in your AppConfig , namely that the name attribute is set incorrectly.这里的问题出在您的AppConfig中,即name属性设置不正确。 As stated in the documentation the attribute name is the:文档中所述,属性name是:

Full Python path to the application应用程序的完整路径 Python

Hence instead of job_main it needs to be set to apps.job_main :因此,需要将它设置为apps.job_main job_main

from django.apps import AppConfig

class JobMainConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'apps.job_main'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM