我试图限制所有博客访问仅经过身份验证的用户,因为默认情况下所有博客文章都是公开的,我使用以下类来覆盖博客路由(例如/blog/myblogs-2(:
class RestrictWebBLog(WebsiteBlog):
@http.route(auth='user')
def blogs(self):
return super(RestrictWebBLog, self).blogs()
@http.route(auth='user')
def blog_post(self):
return super(RestrictWebBLog, self).blog_post()
@http.route(auth='user')
def blog(self):
return super(RestrictWebBLog, self).blog()
它似乎有效,因为尝试访问任何博客时都需要登录,但是输入凭据后,会出现以下错误:
错误信息:
blog() got an unexpected keyword argument 'blog'
Traceback (most recent call last):
File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 203, in _dispatch
result = request.dispatch()
File "/opt/odoo/odoo/http.py", line 833, in dispatch
r = self._call_function(**self.params)
File "/opt/odoo/odoo/http.py", line 344, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/odoo/http.py", line 337, in checked_call
result = self.endpoint(*a, **kw)
File "/opt/odoo/odoo/http.py", line 939, in __call__
return self.method(*args, **kw)
File "/opt/odoo/odoo/http.py", line 517, in response_wrap
response = f(*args, **kw)
TypeError: blog() got an unexpected keyword argument 'blog'
我认为您必须在与原始函数相同的函数中编写参数。
比如函数blogs()
,在原来的函数中有更多的参数,比如
def blogs(self, page=1, **post):
因此,尝试像在原始函数中一样使用所有参数进行定义。