跳至內容
選單
此問題已被標幟
1 回覆
2038 瀏覽次數

Do you have an example of how to pass a value from a controller to an OWL template? I haven't found a single article discussing this.

頭像
捨棄
最佳答案

Hi,

For passing the value from the controller to the template, try to use the following code:

Python:# -*- coding: utf-8 -*-

from odoo import http

from odoo.http import request


class ExampleController(http.Controller):


    @http.route('/example', auth='public', website=True)

    def example(self):

        message = "Hello, World!"

        return request.render('your_module.example_template', {'message': message})


XML:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <template id="example_template" name="Example Template">
        <t t-call="website.layout">
            <div id="wrap">
                <div class="container">
                    <h1 t-esc="message"/>
                </div>
            </div>
        </t>
    </template>
</odoo>



Hope it helps.


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
6月 24
1525
2
7月 25
511
0
1月 25
923
0
12月 24
1704
0
9月 24
932