1. Install the swagger package
pip install drf-yasg
2. Configure the setting file
3. Create a new views.py file configuration in the setting directory at the same level
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
schema_view = get_schema_view(
openapi.Info(
title="API",
default_version='v1',
description="系统API文档",
),
public=True,
permission_classes=(permissions.AllowAny,),
)
4. Configure the main routing file urls.py
path('swagger/', schema_view.with_ui('swagger',
cache_timeout=0), name='schema-swagger-ui'),
path('api_doc/', schema_view.with_ui('redoc',
cache_timeout=0), name='TBoss Api'),
visit swagger