一.搭建開發環境python
pip install virtualenv django
[root@master djiango]# find / -name virtualenv
/usr/local/bin/virtualenvvim
[root@master h1]# source bin/activate
(h1) [root@master h1]#
(h1) [root@master h1]#bash
此時已經進入到虛擬環境;app
(h1) [root@master h1]# deactivate #退出虛擬環境
[root@master h1]#this
[root@master .virtualenvs]# vim ~/.bashrc url
14 export WORKON_HOME=$HOME/.virtualenvs 15 source /usr/local/bin/virtualenvwrapper.sh
[root@master .virtualenvs]# virtualenv -p /usr/local/bin/python3.5 h1
[root@master .virtualenvs]# virtualenv -p /usr/local/bin/python3.5 py35env
[root@master .virtualenvs]# workon h1
/usr/local/bin/python: No module named virtualenvwrapper
/usr/local/bin/python: No module named virtualenvwrapperspa
[root@master .virtualenvs]# pip install virtualenvwrapper設計
[root@master .virtualenvs]# workon h1
(h1) [root@master .virtualenvs]# workon py35env
(py35env) [root@master .virtualenvs]# 3d
###############在虛擬環境下安裝django##################
(py35env) [root@master .virtualenvs]# workon h1
You have new mail in /var/spool/mail/root
(h1) [root@master .virtualenvs]# pip install django==1.8.2
Collecting django==1.8.2
Downloading Django-1.8.2-py2.py3-none-any.whl (6.2MB)
100% |████████████████████████████████| 6.2MB 41kB/s
Installing collected packages: django
Successfully installed django-1.8.2
(h1) [root@master .virtualenvs]# pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
Django (1.8.2)
pip (9.0.1)
setuptools (36.6.0)
wheel (0.30.0)
(h1) [root@master .virtualenvs]#
[root@master ~]# cd /root/.virtualenvs/h1/lib/python3.5/site-packages/ [root@master site-packages]# ll total 44 drwxr-xr-x 18 root root 4096 Oct 31 15:04 django drwxr-xr-x 2 root root 4096 Oct 31 15:04 Django-1.8.2.dist-info -rw-r--r-- 1 root root 126 Oct 31 14:55 easy_install.py drwxr-xr-x 11 root root 4096 Oct 31 14:55 pip drwxr-xr-x 2 root root 4096 Oct 31 14:55 pip-9.0.1.dist-info drwxr-xr-x 5 root root 4096 Oct 31 14:55 pkg_resources drwxr-xr-x 2 root root 4096 Oct 31 14:55 __pycache__ drwxr-xr-x 5 root root 4096 Oct 31 14:55 setuptools drwxr-xr-x 2 root root 4096 Oct 31 14:55 setuptools-36.6.0.dist-info drwxr-xr-x 5 root root 4096 Oct 31 14:55 wheel drwxr-xr-x 2 root root 4096 Oct 31 14:55 wheel-0.30.0.dist-info
在虛擬環境建立django項目:
(h1) [root@master ~]# mkdir projects (h1) [root@master ~]# cd projects/ (h1) [root@master projects]# django-admin startproject test1 You have new mail in /var/spool/mail/root (h1) [root@master projects]# ls test1 (h1) [root@master projects]# cd test1/ (h1) [root@master test1]# ls manage.py test1
(h1) [root@master test1]# ls
__init__.py settings.py urls.py wsgi.py
(h1) [root@master test1]# tree
.
├── manage.py
└── test1
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
二.設計模型