Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
9137 Представления

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
2725
2
июн. 24
4824
1
нояб. 24
1429
1
апр. 23
2764
7
февр. 23
9391