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

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?

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

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)
Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks a lot, it works!

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 2 21
2596
2
thg 6 24
4682
1
thg 11 24
1257
1
thg 4 23
2591
7
thg 2 23
9153