如何以特定 product.id 的形式给出动作调用?
How to give the action call in form a specific product.id?
我有问题。在我的 template.xml 中,我有一个带有操作的表单标签:
<form action="/my/test/#{product.id}" method="post">
我怎样才能给动作调用一个特定的 product.id。我的意思是当它是 product.id "1" 它应该调用 /my/test/1 ,当它是 product.id "2" = /my/test/2
我该如何处理这个问题?
谢谢
了解您的工作很重要。
如果您想为标签创建动态属性,请在 odoo 中使用。你有两种可能性:
t-att-$name
$name 是您的属性名称。
示例
<t t-set="class" t-value="['class1','class2]"/>
<span t-att-class="class[0]"/>
html代码return将是
<span class="class1"/>
它用来评估代码的 t-att-$name。
t-attf-$name
与前面相同,但参数是格式字符串而不仅仅是表达式,通常用于混合文字和非文字字符串:
例子
<t t-set="class" t-value="['class1','class2]"/>
<span t-attf-class="mainclass #{class[0]}"/>
<span t-attf-class="mainclass #{class[1]}"/>
html代码return将是
<span class="mainclass class1"/>
<span class="mainclass class2"/>
在您的情况下,您需要将文字值与变量连接起来。
您必须使用 t-attf-$name
<form t-attf-action="/my/test/#{product.id}" method="post">
现在在python代码中,需要创建一个动态路由。
在你的情况下,你的路由必须是这样的。
@http.route(['/my/test/<int:product_id>/'], type='http', auth="user", website=True)
def my_test_product(self, product_id, **kwargs):
#your code
return request.website.render("your_model.template_id")
我有问题。在我的 template.xml 中,我有一个带有操作的表单标签:
<form action="/my/test/#{product.id}" method="post">
我怎样才能给动作调用一个特定的 product.id。我的意思是当它是 product.id "1" 它应该调用 /my/test/1 ,当它是 product.id "2" = /my/test/2
我该如何处理这个问题?
谢谢
了解您的工作很重要。
如果您想为标签创建动态属性,请在 odoo 中使用。你有两种可能性:
t-att-$name
$name 是您的属性名称。
示例
<t t-set="class" t-value="['class1','class2]"/>
<span t-att-class="class[0]"/>
html代码return将是
<span class="class1"/>
它用来评估代码的 t-att-$name。
t-attf-$name
与前面相同,但参数是格式字符串而不仅仅是表达式,通常用于混合文字和非文字字符串:
例子
<t t-set="class" t-value="['class1','class2]"/>
<span t-attf-class="mainclass #{class[0]}"/>
<span t-attf-class="mainclass #{class[1]}"/>
html代码return将是
<span class="mainclass class1"/>
<span class="mainclass class2"/>
在您的情况下,您需要将文字值与变量连接起来。
您必须使用 t-attf-$name
<form t-attf-action="/my/test/#{product.id}" method="post">
现在在python代码中,需要创建一个动态路由。
在你的情况下,你的路由必须是这样的。
@http.route(['/my/test/<int:product_id>/'], type='http', auth="user", website=True)
def my_test_product(self, product_id, **kwargs):
#your code
return request.website.render("your_model.template_id")