讓想我有這樣的路線:路線與同裝飾「瓶」 view_func
app.add_url_rule('/',
view_func=index,
methods=['GET'])
app.add_url_rule('login',
view_func=login,
methods=['GET', 'POST'])
@validate_access()
def index():
#......
@validate_access()
def login():
#......
我有2個端點用同樣的裝飾「@validate_access」。 當我運行這段代碼,我得到
AssertionError: View function mapping is overwriting an existing endpoint function: wrapperAssertionError: View function mapping is overwriting an existing endpoint function: wrapper
我不知道,如果它是一個錯誤或沒有。但請告知我是否有解決方案。
謝謝:)
請加上'@ validate_access'裝飾代碼。看起來它不使用'functools.wraps'。或者你可以嘗試顯式設置'endpoint'名稱:'app.add_url_rule('/','index',index,methods = ['GET'])''''和'app.add_url_rule('/ login','login', login,methods = ['GET','POST'])'。 – tbicr
@tbicr我使用了'wrapps',但仍然在Flask 0.10中出現問題。 http://stackoverflow.com/questions/21352718/python-decroator-with-flask你可以看一下嗎? –