简体   繁体   中英

What is the difference between returning jsonify() and returning make_response from in flask rest API?

What is the difference between post methods return statement?

class User(Resource):
     def post(self):
       #some functionality code
        return jsonify({'messsage':'Success','status_code':200})

class Login(Resource):
    def post(self):
       #some functionality code
        return make_response({'messsage':'Success','status_code':200})

class Resgister(Resource):
    def post(self):
       #some functionality code
        return {'messsage':'Success'},200

With jsonify() you will be able to serialize your return data and in turn return a Response object from Flask, though {'messsage':'Success'},200 will be internally converted to Response object too by Flask. With make_response() you will be able to work with rendering a view(html page or template) as a Response object and will be able to set headers, status codes etc.

jsonify creates a Response with the JSON representation of the given arguments with an application/json mimetype. while make_response is used to set additional headers or can be used to convert a value in response object.

For more information read this: jsonify & make_response

Hope this will help you: :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM