pycharm 将django中多个app放到同个文件夹apps的处理方法

在django中需要创建多个app,这个就需要创建一个apps文件,把所有的app放到同个文件夹,这个比较清楚,看起来也比较规范

首先在项目文件右击―CnewCpython package创建一个apps文件,把所有的app拖入到apps,

pycharm 将django中多个app放到同个文件夹apps的处理方法

弹出对话框把search for references和open moved files in editor不勾选,点击确认,这个时候运行点击run,会出现运行错误

in check_apps_ready
 raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

这时候需要对apps的文件夹右击C选择mark directory as―-选择sources root,再点击run,就可以正常运行了

pycharm 将django中多个app放到同个文件夹apps的处理方法

这个时候基本可以在pycharm中正常使用,但是如果部署的实际环境中就不能这样,需要在setting.py文件中加入

sys.path.insert(0,os.path.join(BASE_DIR,'apps'))

这样就可以在实际部署中正常使用。

相关推荐