Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
9031 Tampilan

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?

Avatar
Buang
Jawaban Terbai

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)
Avatar
Buang
Penulis

Thanks a lot, it works!

Post Terkait Replies Tampilan Aktivitas
0
Feb 21
2637
2
Jun 24
4717
1
Nov 24
1340
1
Apr 23
2698
7
Feb 23
9255