from django.utils.log import AdminEmailHandler
from constance import config
from django.conf import settings
from django.core.mail.message import EmailMultiAlternatives
class ConstanceEmailHandler(AdminEmailHandler):
def send_mail(self, subject, message, html_message=None, fail_silently=False, *args, **kwargs):
# create a list of ADMIN emails here, if you have more then one ADMIN
mail = EmailMultiAlternatives('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject),
message, settings.SERVER_EMAIL, [config.ADMIN1],
connection=self.connection())
if html_message:
mail.attach_alternative(html_message, 'text/html')
mail.send(fail_silently=fail_silently)
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'], # change it to require_debug_true if you want to test it locally.
'class': '<yourproject>.<yourfile>.ConstanceEmailHandler', # path to newly created handler class
'include_html': True
},
1#
可能您已经知道,django-constance
不支持元组。基本上,很难专门检测元组的小部件 对你来说。管理员可以是added/deleted
,所以你怎么可能通过single widget
使其成为动态的呢。。!!(想想所有的django小部件)。所以这里CONSTANCE_ADDITIONAL_FIELDS
也不起作用。在2#
我认为你误解了django constance的工作。 它不会刷新您的django server
。所以MANAGER = CONSTANCE_CONFIG['ADMINS'][0]
是完全错误的(即使使用CONSTANCE_ADDITIONAL_FIELDS
)。您在这里访问constant
值(不是动态的)。 你需要像3#
默认的日志记录配置使用AdminEmailHandler
类,它使用django settings
中的ADMINS
值,而不是constance config
。在因此,一个可能的解决方案可能是创建您自己的
^{pr2}$handler
类,它将使用constance config
中的ADMINS
值。所以把你的setting.py
改成然后创建自己的处理程序类,该类将使用
CONSTANCE_CONFIG
。在然后更改您的
LOGGER
配置。如果您没有自定义的LOGGING
设置,我建议您从django.utils.log
(默认的日志记录)复制默认的记录器配置。并将mail_admins
改为相关问题 更多 >
编程相关推荐