在主页(索引)页面上渲染数据odoo 9

时间:2017-07-27 06:50:28

标签: openerp odoo-9 odoo-10

我想在家(索引)页面上渲染数据,下面是我的例子:

控制器:

import openerp.http as http
from openerp.http import request

class TestController(http.Controller):

    @http.route('/index',auth='public',website=True)
    def list(self,**kw):
        Test9 = http.request.env['test.9']
        arr = Test9.search([])
        print arr
        return http.request.website.render('website.layout',
               {'test9':Test9.search([])
     })

XML

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="test9" name="Test9" page="True">
            <t t-call="website.layout">
                <div class="oe_structure">
                  <div class="container">
                    <center><h3>Details</h3></center>
                    <t t-foreach="test9" t-as="company">
                      <h4><span t-esc="company.name"/></h4>
                      <table class="table-striped table">
                        <tr>
                          <td>Name:</td>
                          <td><span t-esc="company.name"/></td>
                        </tr>
                        <tr>
                          <td>City:</td>
                          <td><span t-esc="company.city"/></td>
                        </tr>
                        <tr>
                          <td>Place:</td>
                          <td>
                            <td><span t-esc="company.place"/></td>
                          </td>
                        </tr>
                      </table>
                    </t>
                  </div>
                </div>
            </t>
        </template>
    </data>
</openerp>

在控制台中运行http://localhost:8069/index后获得两条记录

我的代码中的问题在哪里?

............................................... .................................................. ...............................................

1 个答案:

答案 0 :(得分:1)

试试这个。

import openerp.http as http
from openerp.http import request

class List(openerp.addons.web.controllers.main.Home):

    @http.route('/', type='http', auth='none', website=True)
    def index(self):
       Test9 = request.env['test.9']
       arr = Test9.search([])
       print arr
       return request.render('YOUR_MODULE.test9',
           {'test9':Test9.search([])
       })