flask / flask_restful :从不同蓝图中的另一条路线调用一个蓝图中的路线

flask / flask_restful : calling routes in one blueprint from another route in a different blueprint

我正在开发一个非常基本的 Web 应用程序(使用 flask 和 flask_restful 构建),其中不相关的视图拆分为不同的蓝图。

不同的蓝图处理 class 的不同实例。

现在我想设计一个页面,其中包含这些蓝图正在处理的所有 classes 的状态(属性和值)。该页面是一种控制面板。

为此,我想从不同蓝图中的单个路由(状态页面路由)调用不同蓝图中的所有状态路由(由我定义)。我一直在搜索如何在 Flask / Flask_restful 中进行内部调用,但没有找到任何专门用于此的东西。所以....

  1. 我很想知道如何进行这些内部调用。
  2. 此外,是否有任何问题或惯例反对进行内部调用。
  3. 我还考虑过使用 Requests 模块来调用 requests,但这感觉更像是 hack。这是我唯一的选择吗???如果是,有没有一种方法我不必像在烧瓶中使用接近 url_for() 的东西那样对其中的 url 进行硬编码?

谢谢..:)

  1. I would love to find out how to make these internal calls.

答案:使用 url_for() 或 Requests 模块,就像您对任何其他 post 或 get 方法所做的那样。

  1. Also, is there any problem or convention against making internal calls ?

答:找了很久也没找到。

  1. I also thought of making use of the requests calls using Requests module, but that feels more like a hack. Is this the only option I got??? If yes, is there a way I don't have to hard code the url in them like using something close to url_for() in flask??

A​​ns:如果您不想使用 Requests 模块,url_for() 是最简单、最干净的选择。硬编码路径是唯一的选择。