【问题标题】:django-notification changing default templatedjango-notification 更改默认模板
【发布时间】:2013-03-15 01:50:30
【问题描述】:

每次用户修改、创建或删除数据库条目时,我都在尝试使用 django-notification 向管理员发送电子邮件。问题是,虽然我创建了通知类型并确认它们存在,但发送实际电子邮件时,发送的电子邮件如下所示:

You have received the following notice from example.com:

Entry has been changed. <--- this line being the email content


To see other notices or change how you receive notifications, please go to http://example.com

有没有办法删除该电子邮件正文的第一行和最后一行?我不知道这个默认模板在哪里,所以我无法更改它。任何见解将不胜感激!

【问题讨论】:

  • 你是如何安装 django-notification 的?通过 pip、easy_install、apt-get、...?
  • sudo pip install django-notification 是命令。

标签: python django email templates django-notification


【解决方案1】:

您应该找到pip 的默认安装目录。如果您使用 Linux,如果您使用 python2.7,它应该类似于 /usr/local/lib/python2.7/dist-packages。然后找到 django-notification 目录并切换到模板目录。他们来了!

一个好主意是将应用程序复制到您的项目目录并在此处进行更改。

我只是建议你看一下 virtualenv,它会给你更多的灵活性来进行这种分叉。

【讨论】:

  • 我找到了我想要更改的模板文件:/usr/local/lib/python2.7/dist-packages/notification/templates/notification/email_body.txt。但是,它是写保护的,这意味着我所做的任何更改都无法保存。我可以在管理员中覆盖这个模板吗?我尝试在我的模板文件夹中为同名项目制作模板的更改版本,但它似乎没有任何效果。
  • 你应该将整个应用程序/usr/local/lib/python2.7/dist-packages/notification/复制到你的项目目录,用sudo chown -R login directory更改所有权,然后你就可以编辑你想要的任何东西了。
【解决方案2】:

更改系统库不是一个好主意。您可以在您的应用中执行此操作:

1) 在 settings.py 中将notification 应用放在你的应用下方

 INSTALLED_APPS = (
      # ...
      'your_app',
      'notification',
      # ...
 )

2) 在your_app/templates/notification/ 目录中创建基础模板集:

  • short.txt
  • notice_settings.html
  • notice.html
  • full.txt
  • full.html
  • email_subject.txt
  • email_body.txt
  • base.html

【讨论】:

  • 我不建议更改系统库,而是复制一个 pip 包来编辑它——避免重新创建所有模板的需要。即使我理解你的意见,我的答案是否值得降级?
  • 你是对的,抱歉。一旦有人接受我的编辑,就会撤消。当发生这种情况时,你可以告诉我。
猜你喜欢
  • 2013-05-11
  • 2022-10-23
  • 2019-05-29
  • 1970-01-01
  • 1970-01-01
  • 2011-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多