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

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!

Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.พ. 21
2604
2
มิ.ย. 24
4698
1
พ.ย. 24
1280
1
เม.ย. 23
2622
7
ก.พ. 23
9175