[英]How to call Python Controller function in Javascript Odoo 10
我是这项技术的新手。 请多多包涵:)谢谢
您对如何使用 ZDE9B9ED78D7E219DCEEFFEE780E 调用 python controller function 有任何想法吗? 我总是收到跨域浏览器错误。 所以我尝试了这个,
.py
@http.route('/custom/createdb', type='json', auth="public", methods=["POST"], website=True)
def createdb(self, db_name):
session = self._authenticate()
if not session:
return json.dumps(False)
# create a new database
headers = {'Content-Type': 'application/json'}
create_db_url = "http://localhost:8090/custom_api/create_db"
data = {"jsonrpc": 2.0, "params": { "name": db_name } }
_logger.debug("Creating database...")
r = session.post(url=create_db_url, data=json.dumps(data), headers=headers)
if r.ok:
return json.dumps(True)
else:
return json.dumps(False)
.js
var session = require('web.session');
$(function()
{
$("#start_trial").click(function()
{
session.rpc('/custom/createdb',
{
// how to get data here
}).then(function (result)
{
// result
});
});
});
刚刚解决了我自己的问题。
var db_name = $("input[name='partner_name']").val();
session.rpc('/custom/createdb', {
db_name : db_name
}).then(function() {
console.log("Creating database");
}, function () {
console.log("calling /custom/createdb caused an exception!");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.