I need to add a python decorator to the Flask route functions (basically I edited the code here )
def requires_admin(f): def wrapper(f): @wraps(f) def wrapped(*args, **kwargs):
and use it, as it will be in order:
@app.route('/admin/action') @requires_admin def AdminAction():
But use it as if it would have an error:
@app.route('/admin/action/<int:id>') @requires_admin def AdminAction(id):
In Flask 0.10, I get such errors (I just updated from Flask 0.9 to 0.10, and in Flask 0.9 there is no such grammatical error):
@requires_admin File "/usr/local/lib/python2.6/dist-packages/Flask-0.10.1-py2.6.egg/flask/app. py", line 1013, in decorator self.add_url_rule(rule, endpoint, f, **options) File "/usr/local/lib/python2.6/dist-packages/Flask-0.10.1-py2.6.egg/flask/app. py", line 62, in wrapper_func return f(self, *args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/Flask-0.10.1-py2.6.egg/flask/app. py", line 984, in add_url_rule 'existing endpoint function: %s' % endpoint) AssertionError: View function mapping is overwriting an existing endpoint functi on: wrapper
I am new to decorator materials, how can I fix this error?
python flask decorator
James king
source share