python - Flask-restplus:有什么方法可以大摇大摆地对命名空间进行排序?
问题描述
Namespace
将条目添加到 Api 后,有什么方法可以对它们进行排序?
我正在关注文档,流程(AFAIK)似乎是:
a) 创建 API:
api = Api(version="1.0",
title="MahApi",
description="Mah Nice Little API",
doc="/swagger-ui",
strict_slashes=False)
b) 定义命名空间:
ns = Namespace("sample_namespace",
description="sample module api",
path='/sample_one')
...
@ns.route('/test1', endpoint='sample_ns_test1')
class TestApi(Resource):
def get(self):
df = mah_service.get_some_data()
return jsonify(json.loads(df.to_json(orient='records')))
c) 向 API 添加命名空间:
api.add_namespace(mah_sample_ns)
我面临的一个问题(尽管它是一个装饰性但令人讨厌的问题)是命名空间没有以任何方式进行排序。看来我需要自己在代码中手动对命名空间进行排序。有没有更聪明的、pythonic 的方式来大摇大摆地对命名空间进行排序?
解决方案
我可能为时已晚,但我一直在想同样的事情,但使用 flask_restx 所以发布这个希望能帮助其他人。但它似乎按照您的命名空间的导入顺序进行。
例如:
from rest.endpoints.Episodes import ns as episodes_namespace
from rest.endpoints.Plex import ns as plex_namespace
from rest.endpoints.Server import ns as server_namespace
将大摇大摆地订购为:
- 剧集
- 丛
- 服务器
尽管:
from rest.endpoints.Server import ns as server_namespace
from rest.endpoints.Episodes import ns as episodes_namespace
from rest.endpoints.Plex import ns as plex_namespace
将大摇大摆地订购为:
- 服务器
- 剧集
- 丛
推荐阅读
- r - 如何将矩阵行转换为零,除了r中的最后一行
- android - 科尔多瓦 fcm 使用 firebase 功能推送通知问题
- android - 在 RecyclerView 中显示数据时,来自 SQLite 的数据序列发生了变化
- javascript - 从数组 React Native 中的数组列出聊天项目
- sitefinity - 更改配置文件自定义字段类型(Sitefinity 6.3)
- css - 根据 Drupal 8 中用户的角色显示/隐藏导航项
- firebase - 如何在防火墙/代理后面使用 Firebase?
- ios - 如何使用 Scroll TransitionStyle 阻止 UIPageViewController 上的点击手势
- python - 如何使用键连接两个数据框并复制匹配值以填充
- functional-programming - 二郎:做个戒指