Odoo JSONRPC服务(http.route类型= json)不起作用
问题描述:
我想在odoo中创建jsonrpc服务。当我创建清洁模块使用DOC https://www.odoo.com/documentation/8.0/howtos/website.html并添加这样的代码Odoo JSONRPC服务(http.route类型= json)不起作用
**[controllers.py]**
@http.route(['/my_academy/ret/'], type='json', auth="public")
def change_size(self):
return {'x': 1, 'y': 2}
尝试从JS连接:
"use strict";
var requestUrl = '/my_academy/ret/';
openerp.jsonRpc(requestUrl, 'call', {})
.then(function (data) {
alert(data['x']);
});
所有做工精细。我收到消息'1'。 当我创建使用DOC https://www.odoo.com/documentation/8.0/howtos/backend.html模块,并添加这样的代码
**[controllers.py]**
@http.route(['/academy/jsonrpc/'], type='json', auth="public")
def return_map(self):
return {'x': 12345, 'y': 2222}
修改js和尝试连接
"use strict";
var requestUrl = '/academy/jsonrpc/';
openerp.jsonRpc(requestUrl, 'call', {})
.then(function (data) {
alert(data['x']);
});
我收到错误
code: 200
data: Object
arguments: Array[0]
length: 0
__proto__: Array[0]
....
debug: "Traceback (most recent call last):↵
File "/home/skif/odoo/openerp/http.py", line 539, in _handle_exception↵
return super(JsonRequest, self)._handle_exception(exception)↵
File "/home/skif/odoo/openerp/addons/base/ir/ir_http.py", line 152, in _dispatch↵
rule, arguments = self._find_handler(return_rule=True)↵
File "/home/skif/odoo/openerp/addons/base/ir/ir_http.py", line 65, in _find_handler↵
return self.routing_map().bind_to_environ(request.httprequest.environ).match(return_rule=return_rule)↵
File "/usr/local/lib/python2.7/dist-packages/werkzeug/routing.py", line 1430, in match↵
raise NotFound()↵
NotFound: 404: Not Found↵"
message: ""
name: "werkzeug.exceptions.NotFound"
__proto__: Object
message: "Odoo Server Error"
__proto__:Object
我在做什么错?为什么我不能使用类似的代码?
答
试试这个代码:
@http.route(['/academy/jsonrpc'], type='json', auth="public", website=True)
def return_map(self, **post):
return {'x': 12345, 'y': 2222}
它可能在你的情况有所帮助。
没有任何变化。 – Skif
你有没有导入你的控制器在init.py – prakash
我试着使用auth =“none” - 什么也没有。如果模块开发的网站,然后一切正常。如果模块开发后端,如https://www.odoo.com/documentation/8.0/howtos/backend.html我有问题。可能是我需要声明任何模块或安全参数? – Skif