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:
- CRM
- e-Commerce
- Financeiro
- Inventário
- PoS
- Projeto
- MRP
Esta pergunta foi sinalizada
1
Responder
9621
Visualizações
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!
Está gostando da discussão? Não fique apenas lendo, participe!
Crie uma conta hoje mesmo para aproveitar os recursos exclusivos e interagir com nossa incrível comunidade!
Inscreva-se| Publicações relacionadas | Respostas | Visualizações | Atividade | |
|---|---|---|---|---|
|
|
0
fev. 21
|
3203 | ||
|
|
2
jun. 24
|
5545 | ||
|
|
1
nov. 24
|
2154 | ||
|
|
1
abr. 23
|
3478 | ||
|
|
7
fev. 23
|
10287 |
To get modules and file path: https://learnopenerp.blogspot.com/2020/06/getting-odoo-modules-and-files-path.html