Development Book V17: Dynamic Routes

Controllers are used by Odoo to set up frontend modules. Then the frontend modules are integrated with these backend modules. For instance, you cannot utilise Odoo's model capabilities if you wish to display sales order details on your website. However, you may retrieve the sales order information from the backend by utilising the controller. The controller's functionality is expanded with modules that include website sales, website blogs, website forums, etc. Controllers make it easy to define links between arbitrary URLs and websites. Pages with dynamic URLs must be created while building a website

For example,

Every product in an online store has a comprehensive view that connects to a separate URL. Example: A "shop" module and adding a product page for each product.

How can a dynamic route be made?

1. Create a controller

                        @http.route('/store/', type='http', auth="user", website=True)
def product_detail(self, product):
    value = {
          'product': product,
    return request.render('store.product_details_page, value)

2. Create a template for the detail page

     <template id="product_details_page" name="Product Detail">
    <t t-call="website.layout">
        <div class="container">
            <div class="oe_structure"/>
            <div class="row">
                <div class="col-12">
                    <div class="col-6">
                        <span t-field="product.image"
                              t-options="{'widget': 'image'}"/>
                    </div> <div class="col-6">
                        <div class="prod_details">
                            <h1 t-field=""/>
                            <span class="prod_price"
                                  t-options="{'widget': 'price'}"/>
                            <ul class="prod_desc_list">
                                <li><t t-esc="product.brand"/></li>
                                <li><t t-esc="product.category"/></li>
                                <li><t t-esc="product.origin"/></li>
                                <li><t t-esc="product.code"/></li> </ul>
                            <span t-field="product.description"/>
                            <div class="prod_buttons">
                                <button class="btn btn-primary"
                                        t-options="{'widget': 'button'}"/>


3. To redirect to the details page, add a button or link to the current view.

 <a t-attf-href="/store/#{}" class="btn btn-primary">
    Goto Product <i class="fa fa-eye"/>


Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message