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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM