コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
9022 ビュー

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!

関連投稿 返信 ビュー 活動
0
2月 21
2618
2
6月 24
4713
1
11月 24
1335
1
4月 23
2683
7
2月 23
9240