第一步 :创建文件夹 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:UsersThe OneEnvsfrontmalllibsite-packagesdjangodbmodelsase.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的文件夹