Dynamic Routes
Odoo uses controllers to configure frontend modules. These frontend modules are integrated into backend modules. For example, if you want to display sales order details on your website, you cannot use Odoo's model functionality. However, using the controller, you can get the sales order details from the backend. The controller extends its functionality with modules such as website sales, website blogs, website forums, etc. Controllers make it easy to define links between arbitrary URLs and websites. When developing a website, it is necessary to create pages with dynamic URLs. For example,
In a website store, each product has its own detailed view of the product that links to different URLs.
Consider having a "shop" module and adding a product page for each product.
How do I create a dynamic route?
To create a dynamic route, follow these three steps.
1.Create a new controller.
@http.route('/store/', type='http', auth="user", website=True)
def product_details(self, product):
Welte = {
'product': product,
}
return request.render('store.product_details', value)
2. Create a new template for the detail page.
<template id="product_details" 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="product.name"/>
<span class="prod_price"
t-field="product.lst_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'}"/>
</div>
</div>
</div>
</div>
</div>
</div>
</t>
</template>
3.Add a link or button to an existing view to redirect the details page.
<a t-attf-href="/store/#{product.id}" class="btn btn-primary">
Goto Product <i class="fa fa-eye"/>
</a>