DRF project access swagger to generate interface documents

1. Install the swagger package

pip install drf-yasg

2. Configure the setting file

insert image description here

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
# swagger文档
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

insert image description here

Guess you like

Origin blog.csdn.net/weixin_43587784/article/details/130582945