用于发送通知的django应用程序。
django-ilmoitin的Python项目详细描述
Django Ilmoitin
一个模板化的django消息传递库
安装
pip install django-ilmoitin
将
django_ilmoitin
添加到INSTALLED_APPS
。
用法
MAILER_EMAIL_BACKEND="your.actual.EmailBackend"
- 在设置中从地址定义默认值
DEFAULT_FROM_EMAIL="your.email@address"
- 在django app中创建一个
notifications.py
文件并注册您的通知类型:
fromdjango_ilmoitin.registryimportnotificationsnotifications.register("event_created","Event created")
- 在django app中创建一个
dummy_context.py
文件并添加虚拟上下文数据:
fromdjango_ilmoitin.dummy_contextimportdummy_contextfrom.modelsimportMyModelmodel=MyModel(foo="bar")dummy_context.context.update({"model":model})
- 在应用程序中导入通知和虚拟上下文。py:
fromdjango.appsimportAppConfigclassExampleConfig(AppConfig):name="example"def__init__(self,*args,**kwargs):super(ExampleConfig,self).__init__(*args,**kwargs)importexample.notificationsdefready(self):importexample.dummy_context
转到django admin并将通知模板添加到通知中
发送通知:
fromdjango_ilmoitin.utilsimportsend_notificationcontext={"foo":"bar",}send_notification("foo@bar.com","event_created",context)
代码格式
这个项目使用^{black
命令:
- 让
black
发挥它的魔力:black .
- 要查看哪些文件
black
将更改:black --check .