API生成文档

安装 

 

pip install django-coreapi
pip install pyyaml
  1. Schema

    # settings.py
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema',

    # 总urls.py
    from rest_framework.schemas import get_schema_view
    schema_view = get_schema_view(title="北网在线 API文档",description="所有API文档")
    path('schema/',schema_view),
    
    
  2. coreapi

    # settings
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',

    # 总urls.py
    from rest_framework.documentation import include_docs_urls
    path('docs/',include_docs_urls(title="北网在线",description="所有API文档"))
    
    
  3. openapi

     

    # settings.py
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema',


    from rest_framework.schemas import get_schema_view

    path('openapi', get_schema_view(
           title="Your Project",
           description="API for all things …"
       ), name='openapi-schema'),
    
    
posted @ 2020-11-26 17:19  Lofty??  阅读(67)  评论(0编辑  收藏  举报