1, install the virtual environment
- First install the virtual environment: pip3 install virtualenv
- Install virtual environments Expansion Pack: pip3 install virtualenvwrapper
- Modify the configuration file .bashrc under the home directory, add the following:
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
- Python3 create a virtual environment ::
mkvirtualenv -p python3 虚拟环境名称(会自动进入虚拟环境)
- Exit the virtual environment: deactivate
- View the created virtual environment: workon + Enter (workon + virtual environment can enter the name of the virtual environment)
- To delete a virtual environment: rmvirtualenv + virtual environment name
2, a virtual environment installation package django
Installation command: pip install the package name
The project required packet as follows: django1.11.2 installed package command: pip install django == 1.11.2
Backup package python: generating pip freeze requirements.txt a file, the file is a list of all third-party libraries, commands are as follows:
备份:pip freeze > requirements.txt
安装:pip install -r requirements.txt
3. Create a project django
- Create a project:
django-admin startproject 项目名称 例如
django-admin startproject test1
- Into the project directory: cd test1
- Create an application:
python manage.py startapp 应用名称 例如 python manage.py startapp booktest
- Install the application to establish the association between the application and the project: name of the application is added under INSTALLED_APPS in test1 / settings.py in to complete the installation