Odoo Help

0

How to get current website_id in controller of Odoo

By
Md. Tanzilul Hasan Khan
on 11/11/16, 4:20 AM 404 views

There are two websites in my odoo. One is localhost and another is 0.0.0.0

I have written following controller to get data from backend -

class website(http.Controller):
@http.route(['/action_get_event_menu_content'], type='json', auth="public")
def get_event_content(self):
website = request.env['website']
website_ids = website.sudo().search([])
#TODO: FILTER CURRENT WEBSITE
value = website_ids.event_content
return value

Here website_id returns two ids (1,2)

How do I get current website_id in the search to filter the website and get the value?

1
@http.route(['/action_get_event_menu_content'], type='json', auth="public", website=True)
def get_event_content(self):
website_id = request.website.id
.....................

By this I can get current website id (which is loading). website=True sends the id.

well

Shameem
on 11/11/16, 5:42 AM
1
Shameem
On 11/11/16, 4:50 AM

Thanzil, 

You can get current base url from your controller

from openerp import http
print http.request.env['ir.config_parameter'].get_param('web.base.url') # BASE URL 

You can identify which website is loaded

I am using odoo 10, so openerp will not work. But I have found a simpler way to do this.

Md. Tanzilul Hasan Khan
on 11/11/16, 5:24 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 11/11/16, 4:20 AM
Seen: 404 times
Last updated: 11/11/16, 5:26 AM