Skip to Content
Menu
This question has been flagged
3 Replies
3104 Views

Hi, i'm trying to get data and render to home view. I'm inherited view and the layout work but i need render product data and i can't do it.

 my code 

Controllers
class WebsitePersonal(http.Controlle):
    @http.route('/', auth='public',website=True)
    def show_custom_menu(self, **kwargs):
        res = {}
        products = request.env['product.template'].search([])
        res = {
            'productos': products,
        }
        return http.request.render('my_module.id_template',res)

  xml 
<template id="id_template" inherit_id="website.layout">
<xpath expr="//div[@id='inherit_id']/header" position="replace">
 
    <!-- TRYING TO SHOW THE RENDERED ELEMENTS RENDERED -->
    <t t-foreach="productos" t-as="prod">
          <t t-esc="prod.name"/><br/>    
    </t>

   </xpath>
  </template>

but the data is not rendered. Help me please
                      
Avatar
Discard
Author

Sehrish Pakistán I made the view and controller and it works, well more or less because when i try to inherit a home page and render product there, the products are not shown, but when i just render a template calling a website.layout, the products are shown here. Ej: <t t-call="website.layout"> </t> .

I need inherit home page to show product there, but i don't know how I can do it

Author Best Answer


You can solve it, in case someone has the same problem or something similar, the solution is: inherit the controller instead of the view. An example code would be:

from odoo import http
from odoo.addons.sale.controllers.onboarding import OnboardingController # Import the class
class CustomOnboardingController(OnboardingController):  # Inherit in your custom class
@http.route('/sales/sale_quotation_onboarding_panel', auth='user', type='json')
def sale_quotation_onboarding(self):
res = super(CustomOnboardingController, self).sale_quotation_onboarding()
# Your code goes here
return res


Avatar
Discard