return {'type': 'ir.actions.act_url',
'url': '/linkedin/post',
'target': 'self',
'context': {
'res_id': self.id
},
}
@http.route('/linkedin/post', csrf=False)
def post_to_linkedin(self, **kwargs):
# record_id = int(kwargs.get('res_id'))
res_id = kwargs.get('res_id')
i want to get id in controller but kwargs is empty how to get that
note: i dont want to pass that in url , help me with this guys.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Buchhaltung
- Lager
- PoS
- Project
- MRP
Diese Frage wurde gekennzeichnet
Hi,
context in ir.actions.act_url is not sent to the controller, so kwargs will be empty if you rely on it. If you don’t want to pass the ID in the URL, you can use the session to store the ID before calling the controller:
# Action
self.env['ir.http'].session['res_id'] = self.id
return {
'type': 'ir.actions.act_url',
'url': '/linkedin/post',
'target': 'self',
}
# Controller
@http.route('/linkedin/post', csrf=False)
def post_to_linkedin(self, **kwargs):
res_id = request.session.get('res_id')
# use res_id here
This way, the controller can access the ID without it appearing in the URL.
This is the standard way in Odoo to pass data to a controller securely when you don’t want to use URL parameters.
Hope it helps.
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!
Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!
Registrieren