OpenERP @ http.route('demo_json',type ='``json''')URL不显示JSON数据 [英] OpenERP @http.route('demo_json', type="json") URL not displaying JSON Data

查看:104
本文介绍了OpenERP @ http.route('demo_json',type ='``json''')URL不显示JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在OpenERP Framework中创建 controller .以下是我的代码,我设置了 http.route type="http"

I am create controller in OpenERP Framework. Following is my code and i set 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>"

在修改URL http://localhost:8069/demo_html后,在h1标题标签中向我显示返回结果This is a test后,上面的代码可以完美地工作.

Above code work perfect once i login into openerp after i modify URL http://localhost:8069/demo_html show me return result This is a test in h1 heading tag.

但是我以相同的方式尝试type="json"并添加以下json代码,然后再次尝试调用URL http://localhost:8069/demo_json其无法正常工作,并向我显示错误"Internal Server Error".

But same way i try to type="json" and add following json code and again try to call URL http://localhost:8069/demo_json Its not work properly and show me 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"}

所以我的问题是如何路由json .任何帮助将不胜感激谢谢.

So my question is how to route json. Any help would be appreciate Thank you.

推荐答案

这是因为type="json"type="http"之间存在差异.

This is because there is difference between type="json" and 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.

这篇关于OpenERP @ http.route('demo_json',type ='``json''')URL不显示JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆