Develop a complete enterprise project based on programming. No matter what kind of project, there are basically three different development modes, and these development modes, if the project is analogous to building a house. Are as follows:
-
Native development. Like building a house from zero, building a project from zero, everything is self-implemented
-
Agile development, [framework-based, development tools] from a work-in-progress to a finished product
-
Secondary development, from the company’s original project, or from the open source project, to transform, do not need to hide or delete the function, do not have the function, development integration.
In terms of development speed: secondary development – > Agile development – > native development
In terms of development difficulty: native development – > secondary development – > Agile development
1 In terms of project performance: native development – > Agile development – > secondary development
Markets: Django, Flask, Sanic, Tornado, FastAPI, Twsited
Django basics – environment, installation, etc
There are many different Web frameworks in Python. Django is the most representative of the heavy hitters. Many successful websites and apps are based on Django.
Django is an open source Web application framework written in Python.
Django, which complies with the BSD copyright, was first released in July 2005, and its first official version 1.0 was released in September 2008.
Django uses MVT’s software design patterns, known as Model, View, and Template.
At present, open source software releases generally have two different branch versions: 1. General release: it is often used for some new functions and features, but the maintenance cycle is short and unstable. LongTerm Supper: long maintenance period, stable software version format: large version. Minor version. The revision number Big version average is the core of the content of the project/software architecture changes occur, the previous code has does not apply to the new version Minor version is generally function, delete a function, small version + 1, a function, small version + 1 revision number general appeared a bug is the original code, will be about the code of bug fixes, The value of the revision number is increasedCopy the code
Website: http://www.djangoproject.com
Documents: https://docs.djangoproject.com/zh-hans/3.2/
Installation:
PIP install django PIP install Django ==3.2 https://pypi.douban.com/simple/ douban source https://pypi.tuna.tsinghua.edu.cn/simple tsinghua source using the format: pip install django -i https://pypi.douban.com/simple/Copy the code
A virtual environment
Virtualenvs
1 installation virtualenvs
Dependency libraries for virtual environments
pip install virtualenv
Virtual environment shell operation library, provides a series of global commands
pip install virtualenvwrapper
# compatible with Windows
pip install virtualenvwrapper-win
Copy the code
2 Common Commands
The command | Parameter options | describe |
---|---|---|
workon | Lists all virtual environments in the current system | |
Workon < Virtual environment name > | When entering the virtual environment with the specified name, the name of the virtual environment will appear on the left of the path. When there is the name of the virtual environment, all piPs will operate based on the directory of the corresponding virtual environment | |
Mkvirtualenv < virtual environment name > | -p Specifies the Python parser version | Create a virtual environment with the specified name. A virtual environment is a directory. |
deactivate | Exit the environment inside the virtual environment | |
pip freeze | PIP list lists the packages installed by PIP developers in the current environment, similar to but better than PIP List | |
pip freeze > ./requriments.txt | Requriments. TXT is written blind. Is not constant | Back up the list of all dependent packages in the virtual environment |
pip install -r ./requriments.txt | Restore the list of backup virtual environment packages | |
Rmvirtualenv < Virtual environment name > | Delete the virtual environment with the specified name. |
anaconda
View the current Anaconda system configuration information conda info# List all virtual environments in the current system. * on the left of the environment list indicates the current environment
conda env list You can also use conda info -e
Create a virtual environment
# -n < virtual name > or --name < virtual name >
# indicates the name of the current virtual environment
# python=
# indicates the python version of the current virtual environment. If not, it will be downloaded and installed automatically
# package name >== version number >
# indicates that one or more specified third-party packages are installed when creating the virtual environment
If no version is specified, the latest version of the package supported by the current Python environment will be installed
# note:
When specifying the version of the package, it is possible to fail to create the virtual environment because this version is not available or the current Python environment does not support the current version.
# Therefore, it is recommended that you specify the package version as small as possible, such as django==1.*Conda create -n < virtual environment name > python=< Python version number > < package name 1>==< Version number > < package name 2>... < n > package name# such as:Conda create -n python27 python=2.7 conda create -n python36 python=3.6 pymongo conda create -n mofang python=3.8 flask Celery conda create -n renran python= 0, celery conda create -n renran python= 0Clone the virtual environmentConda create -n < new virtual environment name > --clone< Old virtual environment name >Enter/switch to the specified virtual environment. If no parameter is specified, the global environment is returned to base by default.Conda Activate < virtual environment name >Exit the current virtual environment
conda deactivate
Install/update one or more of the specified packages for the specified virtual environment
PIP install can also be used to install the virtual environmentConda install -n < virtual environment name > < package name 1>==< version number > < package name 2>... < n > package nameUnmount one or more packages for the specified virtual environment
PIP uninstall < package name > can also be used to uninstall the virtual environmentConda remove -n < virtual environment name > < package name 1>==< version number > < package name 2>... < n > package name# Delete the specified virtual environmentConda remove -n < virtual environment name > --allExport the Anaconda package information of the current virtual environment to the environment configuration file environment.yaml
conda env export > environment.yaml
Create a new virtual environment according to the package information in the environment configuration file environment.yaml
conda env create -f environment.yaml
# Check conda version
conda -V
Run the conda update command to update the version of Anaconda. The system will prompt you with complete and correct commandsConda update --prefix < Anaconda installation directory > anaconda### the following command has nothing to do with Anaconda and is related to project deployment/migration.
Check the installed packages in the current virtual environment
pip freeze # Listed here are the packages we installed manually
pip list This list includes not only the packages we installed manually, but also the dependencies that the virtual environment runs
Export all packages in the current virtual environment and record them in requirements.txt
pip freeze > ./requirements.txt
Import all the packages recorded in requirements. TXT into the current virtual environment.
pip install -r requirements.txt
Copy the code