drf 自动生成文档说明

  • 添加url配置
  from rest_framework.documentation import include_docs_urls

  urlpatterns = [
      ...,
      path('docs',include_docs_urls(title='站点后台')),
      ...,
  ]
  • 添加restframework配置
  REST_FRAMEWORK = {
      ...,
      'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema',
    # 或 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'  
      ...,
  }
  • 安装依赖
  pip install coreapi pyyaml
  • 发起访问测试

http://127.0.0.1:8000/docs




版权声明:除特别注明外,本站所有文章均为王晨曦个人站点原创

转载请注明:出处来自王晨曦个人站点 » drf 自动生成文档说明

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注