Suppose that there is a function of the form:
@app.route('/cat/', methods=('GET', 'POST'))
@check_something(check='cat')
def cat():
print 'cat'
return 'cat'
@app.route('/dog/', methods=('GET', 'POST'))
@check_something(check='dog')
def dog():
print 'dog'
return 'dog'
Here I used a decorator called check_something (), what I want to do is check the condition before executing mainfanction. Decorator function code:
def check_something(check=''):
def decorator(f):
@functools.wraps(f)
def decorated_function(*args, **kwargs):
print('check_start')
if check == 'dog':
return jsonify( ret='check dog' )
else:
ctx = f(*args, **kwargs)
return jsonify( ret=ctx )
return decorated_function
return decoration
I am testing it from the client and the android web client, below are the test results:
Android + GET: route 'cat' is OK, route 'dog' is OK;
Web + GET : route 'cat' is OK, route 'dog' is OK;
Android +POST: route 'cat' is OK, route 'dog' is Failed, raise SocketTimeoutException;
Web + POST: i didn't test it.
Why? This is so strange!
Let me talk about some personal assumptions.
1.This is caused by a decorator. * Flask decorator @ app.route () will write the decorated function. And so I added functools.wraps (f) to save the function of the function. But when the program does check_something (check = 'dog'), it did not execute f (* args, ** kwargs), so the flag lost the function of the decorated function. And so the flask loses the answer. I think so.
2. GET ? , - Flask POST. , .
- ? !