安装 swagger
pip install drf_yasg
setting.py 添加 swagger
INSTALLED_APPS = [
....
'drf_yasg',
]
总路由配置 url.py
# 配置 swagger
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from rest_framework import permissions
schema_view = get_schema_view(
openapi.Info(
title="drf接口文档",
default_version='v1.0.0',
description="Test description",
terms_of_service="https://www.gyarmy.com/",
contact=openapi.Contact(email="541750337@qq.com"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)
urlpatterns = [
....
path('doc/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
]
0则评论给“swagger配置”