Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4270 Lượt xem

i tested it using postman and it doesn't work

test_controller.py:

from odoo import http
from odoo.http import request, Response
import json


class TestController(http.Controller):

@http.route("/test", auth='public', type='jsonrpc', csrf=False, method='GET')
def get_test(self, **kw):
print("Test")
response = {'message': "Test Test 123"}
return Response(json.dumps(response), content_type='application/json')
__init__.py:
from . import test_controller

both files are in a folder called controllers




Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

try this way:
test_controller.py:
from odoo import http

from odoo.http import request

import json


class TestController(http.Controller):


@http.route("/test", auth='public', type='json', csrf=False, methods=['GET'])

def get_test(self, **kw):

print("Test")

response = {'message': "Test Test 123"}

return request.make_response(json.dumps(response), headers={'Content-Type': 'application/json'})


init.py:
from . import test_controller





Ảnh đại diện
Huỷ bỏ
Tác giả

didn't work do you want my file structure ? maybe it helps ?

Câu trả lời hay nhất

Hi,

Change the type as json and trigger the end point from the post man and see if it makes any difference. Also try to keep a single db in the instance, if you have multiple use a db filter.


Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

what do you mean by a single db in the instance

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 17
3185
0
thg 9 24
1299
1
thg 3 15
272
1
thg 7 25
2371
1
thg 11 23
12112