Article directory
Django environment installation
1. Installation environment
1.1 Install Python (configure virtual environment)
Since foreign sources are slow, you can add Tsinghua sources via pip.
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
1.1.1 Steps
-
Create a virtual environment
python -m venv django4_2
erp_venv is the name of the virtual environment
Python virtual environment and install it in
erp_venv
a folder in your current directory. A virtual environment can help you isolate the dependent libraries of different projects, thus avoiding library version conflicts between projects. -
Start virtual environment
Enter the virtual environment directory
cd ./Scripts/activate
-
Exit the virtual environment
deactivate
-
Install Django
pip install django
Django is a Python web framework that provides many features such as ORM, authentication, forms, templates, etc., which can help you develop web applications faster and easier.
-
Install DRF
pip install djangorestframework
DRF is a powerful and flexible RESTful framework based on Django, which provides many tools and libraries to help you quickly develop web applications based on RESTful API.
-
Install Django-Filter
pip install django-filter
介绍:Integration with DRF — django-filter 23.2 documentation
Django-Filter is a Django-based library that provides a simple and flexible way to filter querysets of Django models. Django-Filter's API allows developers to use simple query expressions to build and apply complex filters to select and exclude data from query sets.
Through the integration with DRF Spectacular, Django-Filter supports data filtering and query expressed by OpenAPI specifications, and provides a more elegant API specification solution.
-
Install Django Spectacular
pip install drf_spectacular
Introduction: DRF Spectacular is DRF's OpenAPI specification tool. It can automatically build and generate OpenAPI specification documents, and provide convenient API testing tools, making it easier for you to create, test and maintain RESTful APIs. At the same time, it also supports integrated Django Filter, allowing you to filter query data through URL parameters.
1.2 Conda configuration environment
-
conda configures the python interpreter, and the environment is named django4_2
conda create -n django4_2 python=3.8 # 激活环境 conda activate django4_2
-
Install django==4.2 library
pip install django==4.2
-
Install DRF
pip install djangorestframework
-
Install Django-Filter
pip install django-filter
-
In the virtual environment, install the debug_toolbar library
pip install django-debug-toolbar
-
In the virtual environment, install the django_extensions library
pip install django_extensions
reference
DataWhale open source artificial intelligence community
DataWhale-Sweettalk-Django4.2