<legend id='WTwt8'><style id='WTwt8'><dir id='WTwt8'><q id='WTwt8'></q></dir></style></legend>

    <tfoot id='WTwt8'></tfoot>

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

    <i id='WTwt8'><tr id='WTwt8'><dt id='WTwt8'><q id='WTwt8'><span id='WTwt8'><b id='WTwt8'><form id='WTwt8'><ins id='WTwt8'></ins><ul id='WTwt8'></ul><sub id='WTwt8'></sub></form><legend id='WTwt8'></legend><bdo id='WTwt8'><pre id='WTwt8'><center id='WTwt8'></center></pre></bdo></b><th id='WTwt8'></th></span></q></dt></tr></i><div id='WTwt8'><tfoot id='WTwt8'></tfoot><dl id='WTwt8'><fieldset id='WTwt8'></fieldset></dl></div>
      <bdo id='WTwt8'></bdo><ul id='WTwt8'></ul>
    1. 移动 Flask-Restplus Swagger API 文档

      时间:2023-09-28

    2. <legend id='jeV6S'><style id='jeV6S'><dir id='jeV6S'><q id='jeV6S'></q></dir></style></legend>

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

          1. <small id='jeV6S'></small><noframes id='jeV6S'>

              <bdo id='jeV6S'></bdo><ul id='jeV6S'></ul>
                本文介绍了移动 Flask-Restplus Swagger API 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 flask-restplus 在 python 中构建一个宁静的 API.我想让 swagger 文档位于与普通/"不同的位置.

                I'm trying to use flask-restplus to build a restful API in python. I'd like to have the swagger docs located in a different place than the normal "/".

                我正在关注这里的文档并按照说明进行操作.我正在使用 python2.7.3 并有以下代码 ~/dev/test/app.py:

                I'm following the documentation here and have followed the instructions. I'm using python2.7.3 and have the following code ~/dev/test/app.py:

                from flask import Flask
                from flask.ext.restplus import Api, apidoc
                
                app = Flask(__name__)
                api = Api(app, ui=False)
                
                @api.route('/doc/', endpoint='doc')
                def swagger_ui():
                    return apidoc.ui_for(api)
                
                app.register_blueprint(apidoc.apidoc)
                

                当我尝试运行这个 python app.py 我得到:

                When I try to run this python app.py I get:

                Traceback (most recent call last):
                  File "app.py", line 7 in <module>
                    @api.route('/doc/', endpoint='doc')
                  File "/home/logan/.virtualenvs/test/lib/python2.7/site-packages/flask_restplus/api.py", line 191, in wrapper
                    self.add_resources(cls, *urls, **kwargs)
                  File "/home/logan/.virtualenvs/test/lib/python2.7/site-packages/flask_restplus/api.py", line 175, in add_resource
                    super(Api, self).add_resource(resource, *urls, **kwargs)
                  File "/home/logan/.virtualenvs/test/lib/python2.7/site-packages/flask_restful/__init__.py", line 396, in add_resource
                    self._register_view(self.app, resource, *urls, **kwargs)
                  File "/home/logan/.virtualenvs/test/lib/python2.7/site-packages/flask_restful/__init__.py", line 435, in _register_view
                    resource_func = self.output(resource.as_view(endpoint, *resource_class_args,
                AttributeError: 'function' object has no attribute 'as_view'
                

                我不太确定到底出了什么问题,我想我知道我没有从 Resource 继承,而这正是 as_view 通常来自的地方,但文档似乎表明这应该有效.

                I'm not really sure what exactly is going wrong, I guess I understand that I haven't inherited from Resource which is where as_view would normally come from, but the documentation seems to indicate that this should work.

                我们将不胜感激.

                推荐答案

                使用 Flask-Restplus <= 0.8.0 你应该这样写:

                With Flask-Restplus <= 0.8.0 you should write:

                from flask import Flask
                from flask.ext.restplus import Api, apidoc
                
                app = Flask(__name__)
                api = Api(app, ui=False)
                
                @app.route('/doc/', endpoint='doc')
                def swagger_ui():
                    return apidoc.ui_for(api)
                

                注意使用 @app 而不是 @api

                从 v0.8.1(即将发布)开始,您只需编写:

                Starting from v0.8.1 (soon to be released), you will simply have to write:

                from flask import Flask
                from flask.ext.restplus import Api, apidoc
                
                app = Flask(__name__)
                api = Api(app, doc='/doc/')
                

                参见:http://flask-restplus.readthedocs.org/en/latest/swagger.html#swagger-ui

                这篇关于移动 Flask-Restplus Swagger API 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Django REST 框架 + Django REST Swagger + ImageField 下一篇:django-rest-swagger 是否不适用于模型序列化器?

                相关文章

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

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

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