OpenERP @ http.route ('demo_json', type = "json") URL not displaying JSON data

I am creating a controller in the OpenERP Framework. Below is my code and I am installing http.route type="http",

import openerp.http as http
from openerp.http import request

class MyController(http.Controller):

    @http.route('demo_html', type="http")
    def some_html(self):
        return "<h1>This is a test</h1>"

Excellent work on the code after I enter openerp after I changed the URL http://localhost:8069/demo_html, show me the result of the return This is a testin the h1 header tag.

But I also try to type="json"add the following json code and try to call the URL again. http://localhost:8069/demo_jsonIt does not work correctly and will show me an error "Internal Server Error".

import openerp.http as http
from openerp.http import request

class MyController(http.Controller):

    @http.route('demo_html', type="http") // Work Pefrect when I call this URL
    def some_html(self):
        return "<h1>This is a test</h1>"

    @http.route('demo_json', type="json") // Not working when I call this URL
    def some_json(self):
        return {"sample_dictionary": "This is a sample JSON dictionary"}

So my question is how to direct json. Any help would be appreciated Thanks.

+2
source share
2

, type="json" type="http".

type="json":

it will call JSONRPC as an argument to http.route() so here , there will be only JSON data be able to pass via JSONRPC, It will only accept json data object as argument. 

type="http":

As compred to JSON, http will pass http request arguments to http.route() not json data.
+1

, , type = "json", json rpc js.

like :
$(document).ready(function () {
    openerp.jsonRpc("demo_json", 'call', {})
            .then(function (data) {
                $('body').append(data[0]);
            });
    return;
})

, ,

@http.route('demo_json', type="json")
def some_json(self):
    return [{"sample_dictionary": "This is a sample JSON dictionary"}]
0

All Articles