• <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 文档

        Django Rest Framework: How to enable swagger docs for function based views(Django Rest Framework:如何为基于函数的视图启用 swagger 文档)

        <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 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

                    <tbody id='PQ0l9'></tbody>
                • <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'>

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