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

Dear all,

I am working on Odoo 12 and need to read the contents of a file that is located on a "static" folder inside my module folder structure.

I am using "os.getcwd()" and it gives me the root folder of my Odoo instalation.
My problem is, on different installations the "custom modules" (addons_path) can be on different locations and this way, my module may fail to work.

 Can anyone help me get the exact path to my module root folder in order for me to read the file located at "mymodule/static/myfile.txt"?

Thank you all in advance

Best regards

PM

アバター
破棄
最善の回答


from odoo.modules.module import get_module_resource
text_file_path = get_module_resource('mymodule', 'static/src/, 'myfile.txt')

アバター
破棄
著作者

@Ravi,

Thank you very much my friend.

Exactly what I need.

Best regards

get_module_resource was renamed to get_resource_path in Odoo 10

get_resource_path was deprecated in Odoo 17 in favor of tools.misc.file_path

関連投稿 返信 ビュー 活動
1
4月 25
3514
0
3月 24
1306
0
10月 22
2501
0
9月 22
1691
1
7月 22
5383