创建具有多个布局和多语言内容的电子邮件。
fluentcms-emailtemplates的Python项目详细描述
安装
首先安装模块,最好是在虚拟环境中。它可以从pypi安装:
pip install fluentcms-emailtemplates
首先确保为django-fluent-contents配置了项目。
然后添加以下设置:
INSTALLED_APPS+=('fluentcms_emailtemplates','fluentcms_emailtemplates.plugins.emailtext',)FLUENTCMS_EMAILTEMPLATES_PLUGINS=('EmailTextPlugin',)
之后可以创建数据库表:
./manage.py migrate
配置
默认情况下定义以下设置:
FLUENTCMS_EMAILTEMPLATES_LAYOUTS=(# A layout points to a template named:# fluentcms_emailtemplates/emails/{slug}/{layout}.html# fluentcms_emailtemplates/emails/{layout}.html('default',_("Default")),)# Possible plugins to use in the email template.# By default, that is FLUENT_CONTENTS_PLACEHOLDER_CONFIG['email_templates']FLUENTCMS_EMAILTEMPLATES_PLUGINS=('EmailTextPlugin',)# Add extras context data for an e-mail preview.FLUENTCMS_EMAILTEMPLATES_PREVIEW_CONTEXT={}# Optionally allow developers to share email templates between all sites in a multisite setup.FLUENTCMS_EMAILTEMPLATES_ENABLE_CROSS_SITE=False# Enable multisite support by defaultFLUENTCMS_EMAILTEMPLATES_FILTER_SITE_ID=True
用法
在管理员中创建电子邮件模板。 使用以下代码创建电子邮件:
fromemail.utilsimportformataddrfromfluentcms_emailtemplates.modelsimport*template=EmailTemplate.objects.get_for_slug('order-confirmation')email=template.get_email_message(base_url='http://example.org/',context={'order_number':"123-xy"},to=[formataddr(('You','you@example.org')),],)email.send()
提示:为纯文本电子邮件创建单独的模板时,请使用{% autoescape off %}启动该模板。 这样可以避免在纯文本电子邮件中创建html实体。
贡献
如果您喜欢这个模块,分叉它,或想改进它,请让我们知道! 也欢迎拉取请求。:-)