How Odoo returns data to Web pages, mobile, as a backend

Source: Internet
Author: User

The pages here do not include pages that are returned using JINJA2 rendering.

Using jinja2 rendered pages, you can pass parameters to the page directly when you call Template.render (), and the page gets through the El expression.

and corresponding to the General page, the mobile sent over the request, we can only return the data in the case, what should be done?

One: Return text data

If it is a text message, we use JSON as the transmission medium.

In Odoo's controller, store the data in an array, dictionary, object, and then use it to convert to JSON data:

 import json// importing JSON module //= Json.dumps (datas)//return Jsonstr.decode ( ' Unicode_escape ') Return to the person making the request

Report:

How to extract data on the requesting side: To receive a JSON array as an example:

 for (Let i = 0; i < json.length; i++) {// traversal returned to JSON array     var value = Json[i].key// extract content by key   }

Second: Back to Multimedia

For the transmission of multimedia content such as video, audio, picture, etc., we use IO stream form.

 from Import Stringio Import  = request.env[' model name '].sudo (). Search ([(search condition)])return Http.send_file (Stringio (Base64.standard_b64decode (record. Multimedia field)), Filename="The file name can be set by itself, note that the suffix must have, Otherwise the IO stream sent back cannot be parsed correctly ", As_attachment=true)

Where: Multimedia fields can be pgadmin to view the corresponding model database tables, storage content is binary data is the field of the preservation of multimedia content, with the field name to extract binary content.

Since Odoo is using Base64 format to store data by default, we need to decode the extracted binary data with Base64, decode the resulting data string as parameters, pass it to Stringio, generate the data stream, and send it back.

How Odoo returns data to Web pages, mobile, as a backend

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.