Odoo Help

Welcome!

This community 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.

0

How to get current website_id in controller of Odoo

By
Md. Tanzilul Hasan Khan
on 11/11/16, 4:20 AM 148 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@aχoncoms
on 11/11/16, 5:42 AM
1
shameem@aχoncoms
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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