Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
2350 มุมมอง
Getting 404 Error for web controller
in Postman http://localhost:8017/school/schoolrecords
File name: controller/controllers.py

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging

from odoo import http
from odoo.http import request
_logger = logging.getLogger(__name__)
class StudentController(http.Controller):

@http.route('/school/schoolrecords', type='http', auth='public', methods=['GET'])
def getSchoolRecords(self):
school_rec = request.env['school.student'].sudo().search([])
school=[]

for rec in school_rec:
vals={
'id':rec.classid
}
school.append(vals)
return {'student':school}


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

A 404 can happen if:

  1. Request type mismatch – If you’re expecting JSON in the response, set type='json' in the @http.route instead of type='http'. This ensures Odoo automatically serializes your Python dictionary into JSON.
  2. Multiple databases – If you’re running multiple DBs, make sure your odoo.conf has the correct dbfilter (e.g., dbfilter = ^%d$) so the request is routed to the right database.
  3. Testing from outside localhost – If you’re testing from Postman on another machine or service, localhost won’t work. Use ngrok (or similar) to tunnel your Odoo server over HTTPS and get a public URL.

Hope it helps

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hii,

Odoo routes returning JSON should set type='json' or return a Response object (not just a dictionary).

Also, you are using type='http' but returning a plain Python dictionary. For JSON responses, it's better to either:

  • Use type='json' (automatic JSON serialization)
  • Or manually return a Response with headers

here is updated code 
# -*- coding: utf-8 -*-

from odoo import http

from odoo.http import request

import json


class StudentController(http.Controller):


    @http.route('/school/schoolrecords', type='json', auth='public', methods=['GET'])

    def get_school_records(self):

        school_rec = request.env['school.student'].sudo().search([])

        school = []


        for rec in school_rec:

            school.append({

                'id': controllers.py

i hope it is use full

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Controller not working แก้ไขแล้ว
2
มิ.ย. 25
674
3
มิ.ย. 24
3516
1
มี.ค. 23
3922
0
เม.ย. 17
3044
0
มี.ค. 15
4093