第一步 :創建文件夾 apps
第二步:cd到apps下進行app創建
python3 ../manage.py startapp app01
python3 ../manage.py startapp app02
第三步:選中apps文件夾,然后右鍵Make Directory As -> Resoure Root,執行這部操作后,在 INSTALLED_APPS 中注冊的app就不會變成灰色了
第四步 在setting.py 中添加
sys.path.insert(0,os.path.join(BASE_DIR,”apps”))
ps:如果出現注冊的app后顯示
File "C:\Users\The One\Envs\frontmall\lib\site-packages\django\db\models\base.py", line 108, in __new__ "INSTALLED_APPS." % (module, name) RuntimeError: Model class apps.goods.models.GoodsCategory doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
則需要將
在進行 Make Directory As -> Resoure Root 后,在settins的 INSTALLED_APPS 中注冊app的時候, 改成 apps.goods # apps 為自己創建的裝app的文件夾