如何覆盖Flask应用的视图功能

时间:2019-03-15 02:54:47

标签: python flask odoo

我将Flask(0.11.1)与OpenERP一起使用,并且:

  1. 我已经定义了一个网址规则:
@app.route("/sync_order")
def sync_order(): 
   print(1)
  1. 我想在其他OE模块中覆盖它:
@app.route("/sync_order")
def sync_order(): 
   print(1)

# override it

@app.route("/sync_order")
def sync_order2(): 
   print(2)
  1. 但我遇到了错误:
AssertionError: View function mapping is overwriting an existing endpoint function: sync_order
  1. 这是我当前的解决方案:
@app.route("/sync_order")
def sync_order(): 
   print(1)

def sync_order2(): 
   print(2)

# change the mapping of endpoint and view functions
# print `2` now
with app.app_context() as context:
    context.app.view_functions['sync_order'] = sync_order2

这是我的问题:

  1. 这样做可以吗?还是我有潜在的问题?
  2. 还有另一种覆盖视图功能的方法吗?
  3. 不要更改原点功能,因为如果我没有该模块,则该功能应打印1。

谢谢

0 个答案:

没有答案