Reputation: 49
I'm trying to return products information via json using Controllers.
Here is what I try
class api_test(http.Controller):
@http.route('/test', type='json', auth='public')
def index2(self, **args):
p = self.env['product.template'].search_read([], ['name'])
return json.dumps(p)
But I get this error message
'api_test' object has no attribute 'env'
How can I get that Info without using json-rpc? thanks for your help
Upvotes: 1
Views: 1205
Reputation: 49
I found it! I used http.request.env inside odoo module.
class api_test(http.Controller):
@http.route('/test', type='json', auth='public')
def index2(self, **args):
p = http.request.env['product.template'].sudo().search_read([], ['name'])
return json.dumps(p)
Upvotes: 2