Flask's built-in json processing modules jsonify and flaskjsonify

Source: Internet
Author: User

Flask's built-in json processing modules jsonify and flaskjsonify

When we want to return a json data in the view, rather than a template, we can use the built-in json. dumps () in python ().

There is also a similar processing module jsonify in flask,Flask. json. jsonify (* args, ** kwargs)The parameter format is the same as that of the dictionary container.

Import jsonify and return a Respose as a parameter:
From flask import jsonify@app.route ('/_ get_current_user') def get_current_user (): return jsonify (username = g. user. username, email = g. user. email, id = g. user. id)
The returned browsers are as follows:
{"Username": "admin", "email": "admin @ localhost", "id": 42}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.