如何编辑Wagtail在页面提交审核时发送的电子邮件的消息?

huangapple go评论68阅读模式
英文:

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提供的模板。

Django文档详细介绍了如何定位模板以及如何覆盖它们

例如,如果您想覆盖模板/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" in INSTALLED_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.

huangapple
  • 本文由 发表于 2023年3月31日 04:51:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892891.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定