Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
8880 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

Thanks a lot, it works!

Gerelateerde posts Antwoorden Weergaven Activiteit
0
feb. 21
2505
2
jun. 24
4523
1
nov. 24
1090
1
apr. 23
2420
7
feb. 23
8921