나는 django-notification을 사용하여 이메일을 보내려고합니다. 필자는 문서를 읽고 모든 통지 유형, 템플리트 및 management.py를 작성했습니다. 그러나 전자 메일을 보내려고하면 오류와 함께이 디버그 페이지가 표시됩니다. NoticeType 일치하는 쿼리가 없습니다. 여기에 몇 가지 코드가 있습니다. 내 models.py 파일에서django-notification 오류 : NoticeType 일치하는 쿼리가 존재하지 않습니다?
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 = '[email protected]'
EMAIL_HOST_PASSWORD = #not shown
EMAIL_PORT = 587
NOTIFICATION_BACKENDS = [("[email protected]", "notification.backends.email.EmailBackend"),]
#other code....
: 내 settings.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"
: 내 management.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})
죄송합니다 코드가있는 페이지. 거기에 내가 잘못하고있는 것이 있습니까? 뭐가 없니? 어떤 통찰력이라도 대단히 감사하겠습니다!
'./manage.py syncdb'를 실행 했습니까? –
그래, 나는 통지 유형이 admin 백엔드를 검사하여 만들어 졌는지 확인했다. – Kenny
잠깐, "create_model"알림 유형을 만들고 있지만 "create_email"알림 유형을 보내면 문제가 될 수 있습니까? –