gpt4 book ai didi

python - openerp Message_post 错误..NameError : global name '_' is not defined

转载 作者:太空宇宙 更新时间:2023-11-04 01:20:21 26 4
gpt4 key购买 nike

我在表单中创建了一个带有聊天功能的自定义模块。

我想发布自定义消息。但我收到以下错误。

File "/opt/openerp/my_modules/forum/forum.py", line 22, in function_which_post_msg
self.message_post(cr, uid, ids, body=_("New Question has been <b>created</b>"), context=context)
NameError: global name '_' is not defined

我的 .py 文件是

import datetime
import time
import openerp
from openerp.osv import osv, fields


class Course(osv.osv):
_name = "forum.course"
_inherit = ['mail.thread', 'ir.needaction_mixin']

_columns = {
'name' : fields.char(string="Question Title", size=256, required=True),
'description' : fields.text(string="Question Description", required=True),

}


def function_which_post_msg(self, cr, uid, ids, context=None):
self.message_post(cr, uid, ids, body=_("New Question has been <b>created</b>"), context=context)

def create(self, cr, uid, ids, context=None):
self.function_which_post_msg(cr, uid, ids, context=context)

最佳答案

尝试将其导入您的 .py 文件

来自 openerp 导入工具

从 openerp.tools.translate 导入 _

_ 用于在事件用户的语言根据更改时翻译消息。它翻译您的 .po 文件中的消息。

关于python - openerp Message_post 错误..NameError : global name '_' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21671417/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com