İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
11649 Görünümler

I am using odoo community v13. I want user to redirect to '/abc' url of website after json method's execution. How to do that?
Thanks in advance.

I did like this:
ex:

@http.route(['/my/jsonurl/'], type='json',auth='public')

def redierct_url(self, **kw):
    // my code

    return request.redirect('/abc')


Avatar
Vazgeç
En İyi Yanıt

Depending on your usecase, you may be able to write/extend the JavaScript Code. During my research I did not find a built-in way to perform redirects with the website frontend Odoo JSON API (using JavaScript _rpc requests). Finally, I used a similar approach as you can see in 

\https://github.com/odoo/odoo/blob/14.0/addons/portal/static/src/js/portal_signature.js#L128

this._rpc({
...
}).then(function(data) {
if (data.force_refresh) {
if (data.redirect_url) {
window.location = data.redirect_url;
} else {
\window.location.reload();
}
// to avoid triggering chained .then callbacks
return Promise.reject();
}
...
})

where the route returns a dict à la 

return {
'force_refresh': True,
'redirect_url': ...,
)

For the sake of completeness: in the admin backend there is a build-in way, return a URL action

return {
'type': 'ir.actions.act_url',
'url': url,
'target': 'self',
}

Avatar
Vazgeç
En İyi Yanıt

Hi, you can check this:

https://youtu.be/zqFuvqnC3zs

Hope it helps

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ara 21
4020
3
Mar 24
13932
1
Haz 23
3385
0
Tem 17
15044
0
Oca 16
4649