跳转到主要内容

创建电子邮件消息,具有多个布局和多语言内容。

项目描述

fluentcms-emailtemplates

https://img.shields.io/travis/django-fluent/fluentcms-emailtemplates/master.svg?branch=master https://img.shields.io/pypi/v/fluentcms-emailtemplates.svg https://img.shields.io/badge/wheel-yes-green.svg https://img.shields.io/pypi/l/fluentcms-emailtemplates.svg https://img.shields.io/codecov/c/github/django-fluent/fluentcms-emailtemplates/master.svg

一个电子邮件模板系统,使用django-fluent-contents块来定义电子邮件模板。

功能

  • 多语言内容。

  • 多站点支持。

  • 自定义布局(=Django模板)。

  • 自定义上下文变量

安装

首先安装模块,最好是在虚拟环境中。可以从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 default
FLUENTCMS_EMAILTEMPLATES_FILTER_SITE_ID = True

用法

在管理界面中创建电子邮件模板。使用以下代码创建电子邮件

from email.utils import formataddr
from fluentcms_emailtemplates.models import *

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实体。

贡献

如果您喜欢这个模块,已经进行分支开发,或者想要改进它,请告诉我们!我们也欢迎pull requests。:-)

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

fluentcms-emailtemplates-2.0.tar.gz (27.2 kB 查看哈希值)

上传时间 源代码

构建分发

fluentcms_emailtemplates-2.0-py2.py3-none-any.whl (37.2 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下支持