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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客戶關係
- e-Commerce
- 會計
- 庫存
- PoS
- Project
- MRP
此問題已被標幟
1
回覆
8856
瀏覽次數
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
|
2476 | ||
|
2
6月 24
|
4514 | ||
|
1
11月 24
|
1070 | ||
|
1
4月 23
|
2401 | ||
|
7
2月 23
|
8887 |
To get modules and file path: https://learnopenerp.blogspot.com/2020/06/getting-odoo-modules-and-files-path.html