I'm rather new to web programming and Flask, and I've recently run into a problem with a website I am trying to create. I currently have a jquery procedure which sends a post request to a view function in Flask. This function simply increments a value in my database, and it's not really necessary for me to return a response after incrementing this value. However, as far as I've seen, view functions in Flask are required to return a Response object. I could of course trivially return some sort of json "was-updated" response, but it's really not important to my application. Does anyone know if the proper way to resolve this issue? Thanks.
Asked
Active
Viewed 4,773 times
9
-
7all requests have responses, it would be fine to return some sort of "trivial" response, would a `204` response be of help to you? http://stackoverflow.com/a/3283126/594589, it includes a response with no body – dm03514 Dec 22 '13 at 00:43
-
@dm03514 turn your comment into an answer to this question. That is the right answer. – iurisilvio Dec 22 '13 at 13:28
-
I concur, a 204 response will work great and Flask will actually strip any body you *do* try to send. – iandouglas Dec 23 '13 at 07:53
1 Answers
11
It's quite simple, just return an empty string with 204 status code:
@app.route('/')
def hello():
# ...
return '', 204

Grey Li
- 11,664
- 4
- 54
- 64