项目根目录下创建apps目录

 

mkdir apps

 

将应用移动到apps目录下

Django 将APP存储至统一目录

 

这里取消  search for references   ,open moved files in edito

Django 将APP存储至统一目录

选择 Add

 

settings.py中导入sys包并加入搜索路径

import os
import sys

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# add search path
sys.path.insert(0, os.path.join(BASE_DIR, "apps"))

 

出现问题:创建app时可能报 CommandError: 'xx' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.

解决方法:临时把settings中的sys.path.insert(0, os.path.join(BASE_DIR, "apps"))注释掉,再去新建app

使用 python manager.py startapp name apps\Core 时,要先注释上面添加的这行 

 

如果是在 PyCharm 中操作,那么在 apps 上右键 Mark Director as 选择 source root, 这样在 PyCharm 中就可以愉快的启动了

 

创建app

python manager.py startapp name [directory]

 

相关文章:

  • 2021-11-07
  • 2022-02-16
  • 2021-10-15
  • 2022-12-23
  • 2021-10-12
  • 2021-06-12
  • 2021-10-27
  • 2021-10-22
猜你喜欢
  • 2021-05-21
  • 2022-12-23
  • 2021-09-10
  • 2021-12-10
  • 2021-10-24
  • 2022-01-07
  • 2021-12-08
相关资源
相似解决方案