Skip to Content
Menu
This question has been flagged

Hi, do you have some examples how to get the data from a python method in a controller using javascript?

.py

@http.route('/saas/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/saas_api/create_db"
        data = {"jsonrpc": 2.0, "params": { "name": db_name } } // how to get this?
        _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 db_name = $('input').attr('contact_name');
session.rpc('/saas/createdb', { db_name: db_name }).then(function (result){ //result }



Error:
TypeError: createdb() takes exactly 2 arguments (1 given)\n","exception_type":"internal_error","message":"createdb() takes exactly 2 arguments (1 given)","name":"exceptions.TypeError","arguments":["createdb() takes exactly 2 arguments (1 given)"]}}
Avatar
Discard
Related Posts Replies Views Activity
7
Jan 24
40517
2
Oct 20
2971
2
Mar 15
300
1
Jan 20
7808
0
Apr 17
2157