swagger配置

安装 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'),
]

原文链接: swagger配置 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( https://gyarmy.com/post-743.html )

发表评论

0则评论给“swagger配置”