Django邮件模板编辑器
项目描述
Django电子邮件模板!
许多项目都有明确定义的一系列事件,这些事件会触发发送电子邮件,因此合理的是将这些事件模板化。
然而,对代码更新和部署进行小的模板调整既繁琐又令人烦恼。
该项目旨在解决此问题 - 在代码中定义模板类型,并在前端编辑实际模板。模板在语法和必需/可选内容上都会进行验证。
本项目旨在解决在支持所有电子邮件客户端时可能遇到的HTML电子邮件模板问题。这也被电子邮件基金会所使用。电子邮件基金会是一个在开发模式下构建初始电子邮件模板的好方法。它将生成单独的HTML文件和CSS文件。
对于电子邮件发送和记录,我们推荐使用例如Django Yubin这样的解决方案。
此项目仅在PostgreSQL数据库上进行了测试。
支持如下
python 3.10, 3.11, 3.12
Django 3.2, 4.2
PostgreSQL
警告
本项目目前处于开发阶段,尚不稳定。
安装
使用pip安装
pip install mail_editor
将‘mail_editor’添加到已安装的应用程序
# settings.py
INSTALLED_APPS = [
...
'mail_editor',
'ckeditor',
...
]
添加URL
# urls.py
url(r'^mail-editor/', include('mail_editor.urls', namespace='mail_editor')),
使用模板
您可以使用以下两个模板。
_base.html,此模板不能由用户编辑。它仅在发送电子邮件时才会渲染。
_outer_table.html,此模板可以由用户编辑,并在管理员中的编辑器中加载。此模板的修改将保存在数据库中。
您可以使用模板以不同的方式。最简单的方式是
from mail_editor.helpers import find_template
def email_stuff():
template = find_template('activation')
context = {
'name': 'Test Person',
'site_name': 'This site',
'activation_link': 'https://github.com/maykinmedia/mail-editor',
}
template.send_email('test@example.com', context)
设置
以下设置是一个示例
MAIL_EDITOR_CONF = {
'activation': {
'name': gettext_noop('Activation Email'),
'description': gettext_noop('This email is used when people need to activate their account.'),
'subject_default': 'Activeer uw account voor {{site_name}}',
'body_default': """
<h1>Hallo {{ name }},</h1>
<p>Welkom! Je hebt je geregistreerd voor een {{ site_name }} account.</p>
<p>{{ activation_link }}</p>
""",
'subject': [{
'name': 'site_name',
'description': gettext_noop('This is the name of the site. From the sites'),
'example': gettext_noop('Example site'),
}],
'body': [{
'name': 'name',
'description': gettext_noop('This is the name of the user'),
'example': gettext_noop('Jane Doe'),
}, {
'name': 'site_name',
'description': gettext_noop('This is the name of the site. From the sites'),
'example': gettext_noop('Example site'),
}, {
'name': 'activation_link',
'description': gettext_noop('This is the link to activate their account.'),
'example': gettext_noop('/'),
}]
},
...
}
以下设置很有用
# These settings make sure that CKEDITOR does not strip any html tags. like <center></center>
CKEDITOR_CONFIGS = {
'mail_editor': {
'allowedContent': True,
'contentsCss': ['/static/css/email.css'], # Enter the css file used to style the email.
'height': 600, # This is optional
'entities': False, # This is added because CKEDITOR escapes the ' when you do an if statement
}
}
您可以使用以下方式设置所有邮件模板的模板变量。
# static dictionary
MAIL_EDITOR_BASE_CONTEXT = {
'url': 'http://www.maykinmedia.nl',
}
# import path to callable that returns a dictionary
MAIL_EDITOR_DYNAMIC_CONTEXT = "dotted.path.to.callable"
安装
使用pip安装
pip install mail_editor
本地开发
要本地安装和开发库,请使用以下命令
.. code-block:: bash
pip install -e .[tests,coverage,release]
当通过django-admin
运行管理命令时,请确保将根目录添加到python路径中(或使用python -m django <command>
)
export PYTHONPATH=. DJANGO_SETTINGS_MODULE=testapp.settings
django-admin check
# or other commands like:
django-admin migrate
django-admin createsuperuser
django-admin runserver
# django-admin makemessages -l nl
项目详情
下载文件
下载适用于您的平台文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
构建分布
mail_editor-0.3.7.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ee905098b5e35bdf34ac534c705dfb6316b5ede50d343aab5e570f53ddc714c2 |
|
MD5 | 51a1d24b5fab722ed693acbeafd30e25 |
|
BLAKE2b-256 | b310440c6e621f167b54eb3785fefed949c80db3eed5b23df4cd05a0b3c8b677 |
mail_editor-0.3.7-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 9517e14030adc84d20a6dc417c9d8ac8fc9190b004fd5b0e1c58d619e958874f |
|
MD5 | 0925352a19c492b791bbe2dbe07ce229 |
|
BLAKE2b-256 | 6c1f6d0eb2fdb03a6fcac6cb439b37be753b923043d6f740acd85fbb3e152533 |