1

我正在尝试覆盖 odoo 11 中网站模块中的索引方法。

以下是我的代码

from odoo import http
from addons.website.controllers.main import Website


class Home(Website):

@http.route(['/', '/index', '/home'], type='http', website=True, auth='public')
def index(self, **kw):
    super(Website, self).index(**kw)
    return http.request.render('my_website.home')

我在 my_website 中创建了一个名为 home 的新模板。但是当我访问http://localhost:8069时,它正在为带有页眉和页脚的网站加载标准 odoo 模板。当我访问http://localhost:8069/indexhttp://localhost:8069/home时,它​​会抛出 404 错误。它不会把我的新模板带回家。

我已经提到了这个 SO question How to change default page of odoo with other webcontroller odoo 9.0但不起作用。

4

1 回答 1

1

问题解决了。您必须从odoo.addons导入,而不是从addons导入。

from odoo.addons.web.controllers.main import Website


class MyHome(Website):

@http.route(['/', '/index', '/home'], type='http', website=True, auth='public')
def index(self, **kw):
    return http.request.render('my_website.home')

然后使用您的模板进行渲染。

于 2018-03-15T04:32:24.870 回答