我正在尝试使用 django-notification 发送电子邮件。我已经按照文档创建了所有通知类型、模板和 management.py。但是,当我尝试发送电子邮件时,显示此调试页面并显示错误:NoticeType 匹配查询不存在。这是一些代码。
在我的 management.py 文件中:
from django.conf import settings
from django.db.models import signals
from django.utils.translation import ugettext_noop as _
if "notification" in settings.INSTALLED_APPS:
from notification import models as notification
def create_notice_types(app, created_models, verbosity, **kwargs):
notification.NoticeType.create("create_model", _("Model Creation"), _("An entry has been created"))
notification.NoticeType.create("delete_model", _("Model Deletion"), _("An entry has been deleted"))
notification.NoticeType.create("edit_model", _("Model Change"), _("An entry has been changed."))
signals.post_syncdb.connect(create_notice_types, sender=notification)
else:
print "Skipping creation of NoticeTypes as notification app not found"
在我的 settings.py 文件中:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'departments',
'notification'
)
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'texturamail@gmail.com'
EMAIL_HOST_PASSWORD = #not shown
EMAIL_PORT = 587
NOTIFICATION_BACKENDS = [("texturamail@gmail.com", "notification.backends.email.EmailBackend"),]
#other code....
在我的 models.py 文件中:
def model_create_edit(sender, **kwargs):
instance = kwargs.get('instance')
user, first_name, last_name = instance.user, instance.user.first_name, instance.user.last_name
if kwargs['created']:
notification.send([user], "create_email", {'user':user, 'first':first_name, 'last':last_name})
else:
notification.send([user], "edit_email", {'user':user, 'first':first_name, last':last_name})
def model_deletion(sender, **kwargs):
instance = kwargs.get('instance')
user, first_name, last_name = instance.user, instance.user.first_name, instance.user.last_name
notification.send([user], "delete_email", {'user':user, 'first':first_name, 'last':last_name})
抱歉,页面代码超载。也就是说,我做错了什么吗?有什么遗漏吗?任何见解将不胜感激!