コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
12808 ビュー

Hi

I can't get the model object from controller

class WebExtraControllers(http.Controller):

@http.route('/foo', type='http', auth="public", website=True)
def foo(self, **post):
        # ..........
obj = self.env['res.partner'].function()

But the result is 

AttributeError: 'WebExtraControllers' object has no attribute 'env'

What can I do  ?





アバター
破棄
最善の回答

Please try:

env from request, ie, request.env
eg:

prod_obj = request.env['product.product'].sudo().search([])

or

env = request.env(context=dict(request.env.context, show_address=True, no_tag_br=True))


アバター
破棄
最善の回答

I resolved this issue from looking at existing code and found this one helpful: request.session.model('res.users').browse(id)

アバター
破棄
著作者 最善の回答

I solved

print http.request.env['res.partner'].function()


アバター
破棄
関連投稿 返信 ビュー 活動
2
2月 23
3106
0
4月 20
4184
3
6月 17
14778
0
3月 15
4341
1
5月 25
2992