settings.py
MESSAGE_CLASSES = [
'utils.message.email.Email',
'utils.message.msg.Msg',
'utils.message.wx.WeChat',
'utils.message.dingding.DingDing',
]
msg.py
class Msg(BaseMessage):
def __init__(self):
pass
def send(self, subject, body, to, name):
print('短信发送成功')
__init__.py
import importlib
def send_msg():
for cls_path in settings.MESSAGE_CLASSES:
module_path, class_name = cls_path.rsplit('.', maxsplit=1)
m = importlib.import_module(module_path)
obj = getattr(m, class_name)()
obj.send(subject, body, to, name, )
最后调用:
# 发送消息
message.send_message()
目录结构: