我尝试在odoo中创建jsonrpc服务。当我使用doc https://www.odoo.com/documentation/8.0/howtos/website.html创建了干净的模块并添加了这样的代码
**[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
我做错了什么?为什么我不能使用类似的代码?
答案 0 :(得分:0)
试试这段代码:
@http.route(['/academy/jsonrpc'], type='json', auth="public", website=True)
def return_map(self, **post):
return {'x': 12345, 'y': 2222}
它可能对你的情况有帮助。