django配置虚拟环境

  1. 配置虚拟环境的方法

    方法1:PyCharm中配置虚拟坏境

    方法2:PyCharm终端或者cmd中创建虚拟环境
    ​ 进入到要存放环境的文件夹中 : python -m venv <环境名称>

    方法3:使用virtualenv模块创建:virtualenv <环境名称>

    • 进入到一个现有的虚拟环境下先下载virtulaenv模块

      (myenv) E:\workspace\myenv\Scripts>pip install virtualenvpip install virtualenv
      
    • 查看是否下载成功virtualenv模块

      (myenv) E:\workspace\myenv\Scripts>virtualenv
      Running virtualenv with interpreter E:\python\python.exe
      You must provide a DEST_DIR
      Usage: virtualenv.py [OPTIONS] DEST_DIR
      
      Options:
        --version             show program's version number and exit
        -h, --help            show this help message and exit
        -v, --verbose         Increase verbosity.
        -q, --quiet           Decrease verbosity.
        -p PYTHON_EXE, --python=PYTHON_EXE
                              The Python interpreter to use, e.g.,
                              --python=python3.5 will use the python3.5 interpreter
                              to create the new environment.  The default is the
                              interpreter that virtualenv was installed with
                              (E:\python\python.exe)
        --clear               Clear out the non-root install and start from scratch.
        --no-site-packages    DEPRECATED. Retained only for backward compatibility.
                              Not having access to global site-packages is now the
                              default behavior.
        --system-site-packages
                              Give the virtual environment access to the global
      
    • 使用virtualenv创建新的虚拟环境,注意必须在virtuakenv所在的目录下才能使用virtualenv模块,或者配置环境变量后可以全局使用

      E:\workspace> virtualenv <自己的环境名称>
      或者:
      E:\workspace> virtualenv -p 指定python版本 --no-site-packages <环境名称>
      

    方法4:使用docker

  2. 使用虚拟环境

  • windows

    • 激活环境:进入到Scripts文件夹中执行activate

      E:\workspace\env\firstdjango\Scripts>activate
      
    • 退出环境:deactivate

    (firstdjango) E:\workspace\env\firstdjango>deactivate
    E:\workspace\env\firstdjango>

    
    
    
  1. 项目
  • 安装django:pip install django==2.0.7
  • 项目创建:django-admin startproject <项目名称>
    • __init__.py:配置pymysql
    • urls.py:定义路由与视图函数的关联关系
    • settings.py:配置数据库,配置TEMPLATES等
  • 应用创建:python manage.py startapp <应用名称>
    • views.py:定义视图函数
    • models.py:定义模型
  • 启动方式
    • python manage.py runserver (默认为127.0.0.1:8000)
    • python manage.py runserver port (设置为127.0.0.1:port)
    • python manege.py runserver IP:PORT 自定义启动的IP和PORT
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值