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
- प्रोजेक्ट
- MRP
This question has been flagged
1
Reply
9611
Views
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!
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up| Related Posts | Replies | Views | Activity | |
|---|---|---|---|---|
|
|
0
फ़र॰ 21
|
3201 | ||
|
|
2
जून 24
|
5542 | ||
|
|
1
नव॰ 24
|
2152 | ||
|
|
1
अप्रैल 23
|
3476 | ||
|
|
7
फ़र॰ 23
|
10284 |
To get modules and file path: https://learnopenerp.blogspot.com/2020/06/getting-odoo-modules-and-files-path.html