def header_authenticate(func):
def wrapper():
headers = request.headers
auth = headers.get("X-Api-key")
if auth == 'password':
func()
else:
return jsonify({"401": "Authentication credentials failed"})
return wrapper
@header_authenticate
@app.route('/')
def welcome():
return "<h3>Welcome<h3>"
我希望能够使用上面的装饰器进行身份验证。它不会引发错误,但是会通过。我尝试将装饰器放在下面,但也失败了。
AssertionError: View function mapping is overwriting an existing endpoint function: wrapper