• <bdo id='u5v3S'></bdo><ul id='u5v3S'></ul>
    <tfoot id='u5v3S'></tfoot>

      1. <legend id='u5v3S'><style id='u5v3S'><dir id='u5v3S'><q id='u5v3S'></q></dir></style></legend>

        <i id='u5v3S'><tr id='u5v3S'><dt id='u5v3S'><q id='u5v3S'><span id='u5v3S'><b id='u5v3S'><form id='u5v3S'><ins id='u5v3S'></ins><ul id='u5v3S'></ul><sub id='u5v3S'></sub></form><legend id='u5v3S'></legend><bdo id='u5v3S'><pre id='u5v3S'><center id='u5v3S'></center></pre></bdo></b><th id='u5v3S'></th></span></q></dt></tr></i><div id='u5v3S'><tfoot id='u5v3S'></tfoot><dl id='u5v3S'><fieldset id='u5v3S'></fieldset></dl></div>

      2. <small id='u5v3S'></small><noframes id='u5v3S'>

        Django Rest Framework:如何为基于函数的视图启用 swagger 文档

        时间:2023-09-28

        <small id='ZCvYP'></small><noframes id='ZCvYP'>

                  <tbody id='ZCvYP'></tbody>

              1. <tfoot id='ZCvYP'></tfoot>
              2. <i id='ZCvYP'><tr id='ZCvYP'><dt id='ZCvYP'><q id='ZCvYP'><span id='ZCvYP'><b id='ZCvYP'><form id='ZCvYP'><ins id='ZCvYP'></ins><ul id='ZCvYP'></ul><sub id='ZCvYP'></sub></form><legend id='ZCvYP'></legend><bdo id='ZCvYP'><pre id='ZCvYP'><center id='ZCvYP'></center></pre></bdo></b><th id='ZCvYP'></th></span></q></dt></tr></i><div id='ZCvYP'><tfoot id='ZCvYP'></tfoot><dl id='ZCvYP'><fieldset id='ZCvYP'></fieldset></dl></div>
                  <bdo id='ZCvYP'></bdo><ul id='ZCvYP'></ul>
                  <legend id='ZCvYP'><style id='ZCvYP'><dir id='ZCvYP'><q id='ZCvYP'></q></dir></style></legend>
                  本文介绍了Django Rest Framework:如何为基于函数的视图启用 swagger 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I went through Django REST Swagger 2.1.2 documentation. When I tried with class based views, it was working fine.

                  But i did not find any reference on how to enable swagger for function based views as shown below:

                  @api_view(['GET', 'POST'])
                  def app_info(request): 
                      ...
                      return response
                  

                  Most of my views.py is filled with function based views, just like above.

                  Any help on how to enable the same will greatly appreciated. Thanks!

                  I am using Django: 1.8; Django REST Swagger: 2.1.2; DRF: 3.6.2

                  解决方案

                  You should be able to use @renderer_classes decorator:

                  from rest_framework_swagger import renderers
                  from rest_framework.decorators import api_view, renderer_classes
                  
                  
                  @api_view(['GET', 'POST'])
                  @renderer_classes([renderers.OpenAPIRenderer, renderers.SwaggerUIRenderer])
                  def app_info(request): 
                      ...
                      return response
                  

                  Also, it should be worth mentioning, that if you don't want to use this decorator on every view you can specify DEFAULT_RENDERER_CLASSES in settings

                  EDIT: It seems it's in the docs after all. Check the very bottom of this page: https://django-rest-swagger.readthedocs.io/en/latest/schema/

                  这篇关于Django Rest Framework:如何为基于函数的视图启用 swagger 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python 连接不显示 Swagger UI 下一篇:如何配置“HTTPS"?带有 drf-yasg 自动生成的招摇页面的方案?

                  相关文章

                • <tfoot id='PQ0l9'></tfoot>
                    <i id='PQ0l9'><tr id='PQ0l9'><dt id='PQ0l9'><q id='PQ0l9'><span id='PQ0l9'><b id='PQ0l9'><form id='PQ0l9'><ins id='PQ0l9'></ins><ul id='PQ0l9'></ul><sub id='PQ0l9'></sub></form><legend id='PQ0l9'></legend><bdo id='PQ0l9'><pre id='PQ0l9'><center id='PQ0l9'></center></pre></bdo></b><th id='PQ0l9'></th></span></q></dt></tr></i><div id='PQ0l9'><tfoot id='PQ0l9'></tfoot><dl id='PQ0l9'><fieldset id='PQ0l9'></fieldset></dl></div>

                    <small id='PQ0l9'></small><noframes id='PQ0l9'>

                  1. <legend id='PQ0l9'><style id='PQ0l9'><dir id='PQ0l9'><q id='PQ0l9'></q></dir></style></legend>
                        <bdo id='PQ0l9'></bdo><ul id='PQ0l9'></ul>