Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
8987 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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)
Awatar
Odrzuć
Autor

Thanks a lot, it works!

Powiązane posty Odpowiedzi Widoki Czynność
0
lut 21
2603
2
cze 24
4697
1
lis 24
1280
1
kwi 23
2621
7
lut 23
9174