zoukankan      html  css  js  c++  java
  • Django 将APP存储至统一目录

    项目根目录下创建apps目录

    mkdir apps

    将应用移动到apps目录下

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

    选择 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 appsCore 时,要先注释上面添加的这行 

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

    创建app

    python manager.py startapp name [directory]

  • 相关阅读:
    决策树
    flask数据库的迁移
    flask的查询,一对多,多对多
    django的验证码
    第一讲:python环境配置(python2.7+python3.7)
    pytest
    【TS】-类型兼容性
    HTML--src和href的区别
    JS--为什么null是对象?
    JS--null和undefined的区别
  • 原文地址:https://www.cnblogs.com/linkenpark/p/10893263.html
Copyright © 2011-2022 走看看