Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
8275 มุมมอง

I have created a route with type Json.

@http.route('/test', auth='public', methods=['POST'], type="json", csrf=False)
def recieve_data(self, **kw):
       headers = request.httprequest.headers
       args = request.httprequest.args
       data = request.jsonrequest


So when I receive request using this route everything is fine, but suppose I want to return a different status code like 401, I could not do that with the route which type is json.
I have also tried the bellow method but the problem with this method is that it stops all odoo future requests.


from odoo.http import request, Response
@http.route('/test', auth='public', methods=['POST'], type="json", csrf=False)
def recieve_data(self, **kw):
      headers = request.httprequest.headers
      args = request.httprequest.args 
      data = request.jsonrequest
      Response.status = "401 unauthorized"
      return {'error' : 'You are not allowed to access the resource'}

So in the above example If I set the response status code to 401 all other requests even if they are to different routes will be stopped and its status code changes 401 .

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Found the answer.

https://stackoverflow.com/questions/67646804/how-to-set-response-status-code-in-route-with-type-json-in-odoo-14.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 17
4426
0
พ.ค. 21
3448
1
ก.ค. 17
5711
4
มี.ค. 25
42027
2
ส.ค. 23
3388