在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)