安装并注册swagger -- pip install drf-yasg
INSTALLED_APPS = [
'drf_yasg'
]
在项目 url 配置
2. 配置url
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="这是一个接口文档",
terms_of_service="",
contact=openapi.Contact(email="651205558@qq.com"),
license=openapi.License(name="BSD License"),
),
public=True,
# permission_classes=(permissions.AllowAny,), # 权限类py
)
path('docs/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),