Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
608 Ansichten

I have already created an HTML/CSS static page in Odoo Enterprise without using the default website blocks provided by Odoo. Now I want to make this page dynamic.

Is it possible to make a custom HTML page dynamic in Odoo? If so, what is the best approach to do this?

I'm looking for guidance on how to integrate dynamic content (like data from models) into my custom-built page.

Thanks in advance!

Avatar
Verwerfen
Beste Antwort

Hii,

Create a custom controller
  • In Odoo, dynamic website pages are usually served by controllers written in Python.
  • Your controller method renders a template and passes data (from models) to it.
Convert your static HTML page into a QWeb template
  • Take your existing HTML page and convert it into a QWeb template inside an Odoo module.
  • Add placeholders using QWeb syntax (t-foreach, t-esc, etc.) where you want dynamic data.

Example:

<t t-name="your_module.custom_page">

  <h1>Products List</h1>

  <ul>

    <t t-foreach="products" t-as="product">

      <li><t t-esc="product.name"/></li>

    </t>

  </ul>

</t>

Create a route to serve your page
  • In your controller, define a route URL and render your template with dynamic data.

Example controller snippet:
from odoo import http


class CustomPageController(http.Controller):


    @http.route('/custom/page', type='http', auth='public', website=True)

    def custom_page(self, **kwargs):

        products = http.request.env['product.product'].search([], limit=10)

        return http.request.render('your_module.custom_page', {

            'products': products,

        })

Link your page
  • Access your dynamic page via /custom/page (or your chosen route).
  • This page will now render your original HTML but with real-time data from the Odoo backend.
Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Juli 25
1397
1
Mai 25
867
2
Mai 25
1525
1
Juli 24
3185
0
Aug. 24
341