Python decorator with Flask
问题 I need to add a python decorator to Flask route functions, (basically I edited the code from here) def requires_admin(f): def wrapper(f): @wraps(f) def wrapped(*args, **kwargs): #if not admin: #return render_template('error.html') return f(*args, **kwargs) return wrapped return wrapper and use it like this will be OK: @app.route('/admin/action') @requires_admin def AdminAction(): #NO error if NO parameter But use it like this will have error: @app.route('/admin/action/<int:id>') @requires