英文:
How can I edit the message of the email sent by Wagtail when a page is submitted for moderation?
问题
I'm trying to edit the content of the email sent by Wagtail when a page is submitted for moderation, I've dug into the Wagtail source code and it turns out there is a function called send_mail
which actually sends the emails to all the subscribers when a page is sent for moderation, this function is called by another one called send_notification
which takes some notification templates (HTML and txt files) depending on the type of action (submitted, approved, rejected) of the page, those templates contain the email content and I haven't found the way to override the content of those templates from my Wagtail project.
If someone has done that before, I really appreciate your help.
Thank you!
I'm expecting being able to edit the content of the emails because I want to add some custom fields like comments.
英文:
I'm trying to edit the content of the email sent by Wagtail when a page is submitted for moderation, I've dug into the Wagtail source code and it turns out there is a function called send_mail
which actually sends the emails to all the subscribers when a page is sent for moderation, this function is called by another one called send_notification
which takes some notification templates (HTML and txt files) depending on the type of action (submitted, approved, rejected) of the page, those templates contain the email content and I haven't found the way to override the content of those templates from my Wagtail project.
If someone has done that before, I really appreciate your help.
Thank you!
I'm expecting being able to edit the content of the emails because I want to add some custom fields like comments.
答案1
得分: 1
在任何时候,Django 被要求渲染一个模板,包括在Wagtail的通知邮件模块中,它会依次查找每个在INSTALLED_APPS中列出的应用程序中是否存在具有匹配文件名的模板,并使用它找到的第一个模板。因此,要覆盖wagtail/admin/templates/wagtailadmin/notifications/
中的电子邮件模板之一,您需要:
- 在您的项目中拥有一个应用程序,该应用程序在INSTALLED_APPS中列在
"wagtail.admin"
之上 - 在该应用程序的文件夹
templates/wagtailadmin/notifications/
中创建一个文件,以便它优先于Wagtail提供的模板。
例如,如果您想覆盖模板/wagtail/admin/templates/wagtailadmin/notifications/approved.html(在页面获批准时发送的电子邮件),并且您的项目中有一个名为myapp
的应用程序,该应用程序在INSTALLED_APPS中列在"wagtail.admin"
之上,您应该在路径myapp/templates/wagtailadmin/notifications/approved.html
中创建一个模板。
英文:
Any time Django is asked to render a template - including within Wagtail's notification email module - it will look for a template with a matching filename within each of the apps listed in INSTALLED_APPS in turn, and use the first one it finds. Therefore, to override one of the email templates from wagtail/admin/templates/wagtailadmin/notifications/
, you need to:
- have an app in your project that's listed above
"wagtail.admin"
inINSTALLED_APPS
in your project's settings file - create a file within the folder
templates/wagtailadmin/notifications/
in that app, so that it takes precedence over the template provided by Wagtail.
The Django documentation has more details on how templates are located, and how to override them.
For example, if you want to override the template /wagtail/admin/templates/wagtailadmin/notifications/approved.html (the email sent when a page is approved), and you have an app named myapp
in your project that's listed above "wagtail.admin"
in INSTALLED_APPS
, you should create a template at the path myapp/templates/wagtailadmin/notifications/approved.html
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论