WIN7 +Python2.7.14 + pip + Djanggo1.9

来源:互联网 发布:战争游戏红龙 知乎 编辑:程序博客网 时间:2024/06/07 05:51

1.安装Python2.7

从官网下载2.7版,核对自己的OS系统添加相应的版本,我的版本为WIN7。
https://www.python.org/download/releases/2.7/

支持Python2.7版的最新的Django为1.11版,以后的不支持

2.安装virtualenv

使用pip命令来安装 

我的Python2.7 安装在C盘,进入C:\Python27\Scripts目录下

输入:pip install virtualenv

将会自动下载:我的下载版本号为virtualenv -15.1.0-py2.py3...

3.建立虚拟环境

使用Virtualenv可以建立工程的虚拟环境。 

本地仅安装了Python2.7,故创建一个目录

PS:virtualenv -help

Usage: virtualenv [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=python2.5 will use the python2.5 interpreter
                        to create the new environment.  The default is the
                        interpreter that virtualenv was installed with
                        (c:\python27\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
                        site-packages.
  --always-copy         Always copy files rather than symlinking.
  --unzip-setuptools    Unzip Setuptools when installing it.
  --relocatable         Make an EXISTING virtualenv environment relocatable.
                        This fixes up scripts and makes all .pth files
                        relative.
  --no-setuptools       Do not install setuptools in the new virtualenv.
  --no-pip              Do not install pip in the new virtualenv.
  --no-wheel            Do not install wheel in the new virtualenv.
  --extra-search-dir=DIR
                        Directory to look for setuptools/pip distributions in
                        This option can be used multiple times.
  --download            Download preinstalled packages from PyPI.
  --no-download, --never-download
                        Do not download preinstalled packages from PyPI.
  --prompt=PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --setuptools          DEPRECATED. Retained only for backward compatibility.
                        This option has no effect.
  --distribute          DEPRECATED. Retained only for backward compatibility.
                        This option has no effect.

首先在D盘我创建了虚拟环境的目录。

然后继续执行命令:virtualenv D:\VirtualEnv

此目录下自动添加了

4.启动虚拟环境

进入VirtualEnv文件夹,执行Scripts下的 
Scripts\activate.bat

然后命令行显示为 如下:
(VirtualEnv) D:\VirtualEnv\Scripts>
表示虚拟环境已经启动了。

5.安装 django1.9

执行 pip install django==1.9 


django包就会安装到虚拟环境里。

6.生成工程目录

执行:



重新执行了一遍命令,因为文件名多拼了个字母 'r',现已更改为正确的拼写 learning_log.


7.启动服务器

在建立的工程learning_log文件下面会自动生成了manage.py文件。

cd learning_log

python manage.py migrate   (注:为Django使用的一个数据库)
python manage.py runserver 


在浏览器打开上述网址,显示一个初期画面的话,说明Django的初始安装完毕,可以使用。

其中 URL http://127.0.0.1:8000 即表示在本地计算机(localhost)的端口8000上侦听。localhost是一种只处理当前系统发出的请求,而不允许其他人查看你正在开发的网页的服务器

8.创建APP

在工程下建立APP  Appname:learning_logs

(VirtualEnv) D:\VirtualEnv\Scripts\learning_log>python manage.py startapp learning_logs

查看文件夹下存在以下重要文件:models.py    admin.py  views.py 其中:models.py来定义我们在应用程序中管理的数据。


原创粉丝点击