zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    插入排序
    2019何凯文五夜十篇
    文件
    结构体数组表示
    位运算应用
    条件编译 预处理命令
    文件包含
    带参宏定义
    宏定义有无参数宏定义和带参数宏定义两种
    phpcms v9网站搬家更换域名的方法
  • 原文地址:https://www.cnblogs.com/hhsh/p/12804447.html
Copyright © 2011-2022 走看看