Odoo14 如何在模板中使用变量

时间:2021-07-27 17:12:19

标签: python odoo

我到处寻找解决方案,请帮忙。

    <t t-set="product_image" t-value="aggregated_lines[line]['product_image']"/>
    <t t-set="product_name" t-value="aggregated_lines[line]['name']"/>
    <td style="float:left;width:30%;text-align: center;">
       <img t-att-src="data:image/*;base64,{{product_image}}"
                                t-att-alt="{{product_name}}" />
    </td>

我不能使用变量,如果我直接使用aggregated_lines[line]['product_image'] 会报hash set错误

1 个答案:

答案 0 :(得分:0)

为什么不使用图像 url 而不是 base64 编码的二进制内容?使用此网址格式 /web/image/{record_model}/{record_id}/{image_field}。 假设您的模型是 product.template,代码将是这样的。

<img t-att-src="'/web/image/product.template/{}/product_image'.format(product_id)" t-att-alt="product_name"/>

您也不需要在 {{}} 中使用 t-att-*=""。您将 t-attf-*="" 的语法用于 t-att-*=""。注意额外的f。因此,如果您想使用图像的二进制内容,您的代码必须如下所示。

<img t-attf-src="data:image/*;base64,{{product_image}}"
                            t-attf-alt="{{product_name}}" />
相关问题