django-basic environment configuration

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

  1. 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_venva 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.

  2. Start virtual environment

    Enter the virtual environment directory

    cd ./Scripts/activate
    
  3. Exit the virtual environment

    deactivate
    
  4. 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.

  5. 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.

  6. 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.

  7. 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

  1. conda configures the python interpreter, and the environment is named django4_2

    conda create -n django4_2 python=3.8
    # 激活环境
    conda activate django4_2
    

image-20230813135032638

image-20230813135129709

  1. Install django==4.2 library

    pip install django==4.2
    

    image-20230813142045532

  2. Install DRF

    pip install djangorestframework
    

    image-20230813143340454

  3. Install Django-Filter

    pip install django-filter
    

    image-20230813143617191

  4. In the virtual environment, install the debug_toolbar library

    pip install django-debug-toolbar
    

image-20230813143813760

  1. In the virtual environment, install the django_extensions library

    pip install django_extensions
    

image-20230813143831547

reference

DataWhale open source artificial intelligence community
DataWhale-Sweettalk-Django4.2

Guess you like

Origin blog.csdn.net/weixin_42917352/article/details/132259602