• Model class apps.goods.models.GoodsType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS


    在admin.py注册这个model时,报了个错:

    RuntimeError: Model class apps.goods.models.GoodsType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

    admin是这样写的:

    from django.contrib import admin
    from apps.goods.models import GoodsType
    
    # Register your models here.
    admin.site.register(GoodsType)

    已经把多个应用放到一个文件夹apps,然后在settings也有注册

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'tinymce', # 富文本编辑器
        'user', # 用户模块
        'goods', # 商品模块
        'cart', # 购物车模块
        'order', # 订单模块
    
    ]

    apps的路径也添加进来了

    sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))

    然后仔细看admin的写法,感觉不太对,把apps去掉就正常了,因为在settings已经添加过这个路径了,所以此时只要从具体的app名导入就好

    from django.contrib import admin
    from goods.models import GoodsType
    
    # Register your models here.
    admin.site.register(GoodsType)
  • 相关阅读:
    攻防世界wp--web robots
    kubernetes二: kubernetes 重要组件安装和集群管理
    kibana配置页面跳转
    二进制安装的k8s添加新的node节点
    分布式和微服务的区别
    kubernetes一: 二进制安装k8s集群
    kibana导入导出dashborad
    elk 创建一个只读用户
    x-pack模式下修改es集群密码
    docker基础命令
  • 原文地址:https://www.cnblogs.com/hhsh/p/12804447.html
Copyright © 2020-2023  润新知