Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a view function without returning a response in Flask

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.

like image 217
gratsby Avatar asked Dec 22 '13 00:12

gratsby


1 Answers

It's quite simple, just return an empty string with 204 status code:

@app.route('/')
def hello():
    # ...
    return '', 204
like image 99
Grey Li Avatar answered Oct 19 '22 03:10

Grey Li