Return HTTP status code 201 in flask

前端 未结 9 1162
忘掉有多难
忘掉有多难 2020-12-23 19:58

We\'re using Flask for one of our API\'s and I was just wondering if anyone knew how to return a HTTP response 201?

For errors such as 404 we can call:



        
9条回答
  •  不知归路
    2020-12-23 20:40

    So, if you are using flask_restful Package for API's returning 201 would becomes like

    def bla(*args, **kwargs):
        ...
        return data, 201
    
    

    where data should be any hashable/ JsonSerialiable value, like dict, string.

提交回复
热议问题