Odoo:URL 如果不是授权则找不到

Odoo: URL not found if not auth

我有路由控制器:

@http.route(['/report/yandex_phone_report'], type='http', auth="public", website=True)
def yandex_phone_report(self, **kw):
    page_data = []


    return  http.request.render(self._report_index_page_template, {
        'page_items': page_data

如果我登录 URL /report/yandex_phone_report 显示正常。 如果我没有登录 URL /report/yandex_phone_report 返回 404:

2017-08-02 16:46:09,400 5942 INFO ? werkzeug: 127.0.0.1 - - [02/Aug/2017 16:46:09] "GET /report/yandex_phone_report HTTP/1.1" 404 -

浏览器正在显示:

Not Found

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

我该如何解决?为什么路由不起作用?

发生这种情况是因为它不知道要在哪个数据库中查找 URL。

如果您查看您提供的日志,您会看到在 INFO 之后,您有 ?

2017-08-02 16:46:09,400 5942 INFO ? <- THIS ONE

您会看到一个数据库名称,而不是 ?,如果它知道应该使用哪个数据库的话。

要测试它,您可以先调用:http://localhost:PORT/web?db=YOUR_DB_NAME

这将在浏览器上为给定的数据库设置会话。

那么,调用http://localhost:PORT/report/yandex_phone_report就可以了。

在生产环境中,您需要将其配置为从某处获取数据库名称...从 URL,例如 (http://dbname.example.com:PORT).

在多数据库环境下,您可以拥有 auth='none',但您的模块也需要添加到 odoo.conf server_wide_modules 这样就可以添加路由了。至少在 Odoo 13 中。 https://odoo-development.readthedocs.io/en/latest/admin/server_wide_modules.html