Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1757 Vistas
I am trying to access and display data from one of my custom modules via the Odoo api

But this error appears:
Access to fetch at 'https://xx-xx.xx.xxx/api/get_project' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource . If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Even though I have already made the headers

I use Odoo 17


this my code:

@http.route('/api/get_project', type='http', auth='public', method=['GET'], crsf=False, cors="*")    def get_custom_projects(self, **kwargs):        custom_projects = request.env['custom.project'].search([])        data = []        for project in custom_projects:            project_data = {                'id': project.id,                'name': project.project.name,                'description': project.description,                'project_manager': project.project_manager.name if project.project_manager else None,                'customer': project.customer.name if project.customer else None,                'project_stage': project.project_stage,                'employees': [{'id': emp.id, 'name': emp.name} for emp in project.employee_ids],                'tasks': [{'id': task.id, 'name': task.name} for task in project.task_ids],            }            data.append(project_data)
            headers = {            'Content-Type': 'application/json',            'Access-Control-Allow-Origin': '*',  # Ganti '*' dengan domain yang diizinkan jika perlu        }                return request.make_response(json.dumps(data), headers=[('Content-Type', 'application/json')])


Avatar
Descartar
Mejor respuesta

I do  have the same issue , I have set the cors in controller method, what is going on odoo 


Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
jul 25
1839
1
jun 25
1928
2
may 25
1815
1
may 25
1072
1
feb 25
38