1.安装:
pip install coreapi
pip install django-rest-swagger
2.配置app:
INSTALLED_APPS = [
...
'rest_framework_swagger',
...
]
3.配置url:
from rest_framework.schemas import get_schema_viewfromrest_framework_swagger.renderersimport SwaggerUIRenderer, OpenAPICodec
schema_view = get_schema_view(title=‘API‘, renderer_classes=[SwaggerUIRenderer, OpenAPICodec])
urlpatterns = [
...
path('api-auth/',include('rest_framework.urls')), #drf 认证接口
path('docs/', schema_view, name=‘docs‘),
...
]
4.完成。
网友评论