问题描述
我正在尝试使用 Flask-restx 包部署应用程序烧瓶,但我坚持如何在 prod 服务器上正确显示文档。它在没有任何前缀的情况下在本地运行良好,但在服务器上,文件 url 需要以 my-prefix
为前缀,我正在努力使 swaggerui 文件可从 url 访问:url/my-prefix
这是我的代码:
app = Flask(__name__)
api = Api(
app,version='3.0',title='My API',description='My API',doc="/my-prefix/docs/",prefix="/my-prefix",base_url="/my-prefix"
)
有了这个,我在好的 url 上得到了 swagger.json
,但在文档页面的代码源中没有正确的引用。 swaggerui 文件在文档页面的代码源中没有得到很好的引用,并且无法从 url/my-prefix/swaggerui/files
访问。
所以我添加了这个:
@apidoc.apidoc.add_app_template_global
def swagger_static(filename):
return f"/my-prefix/swaggerui/{filename}"
api = Api(
app,base_url="/my-prefix"
)
@api.documentation
def custom_ui():
return render_template("swagger-ui.html",title=api.title,specs_url="/my-prefix/swagger.json")
这样,在文档页面的代码源(url/my-prefix/swaggerui/myfile
和 url/my-prefix/swagger.json
)中可以方便地引用 swaggerui 文件和 swagger.json 文件,但是无法从此 URL 访问 swaggerui 文件。你知道我应该添加什么才能在这个网址上访问它吗:url/my-prefix/swaggerui/myfile
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)