콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
8985 화면

I want to use a JSON file of data in my module. I put the JSON file in the static folder. I want to open and read it in a controller but I get a 'No such file or directory' error. Any suggestions?

아바타
취소
베스트 답변

Hi,

you can use get_module_resource function to get the right path of the file.

import json
from odoo.modules.module import get_module_resource


json_file_path = get_module_resource('your_module', 'static/, 'you_file.json')
with open(json_file_path) as f:
    data = json.load(f)
아바타
취소
작성자

Thanks a lot, it works!

관련 게시물 답글 화면 활동
0
2월 21
2603
2
6월 24
4697
1
11월 24
1278
1
4월 23
2621
7
2월 23
9174