1#可能你已经知道了,django-constance不支持元组.基本上,特别难以检测元组的小部件
在你的情况下.可以添加/删除ADMINS,以便您可以通过单个小部件使其动态化.!!(想想所有的django小部件).所以在这里
CONSTANCE_ADDITIONAL_FIELDS也不起作用.
2#我认为你误解了django constance的工作.
它不会刷新您的django服务器.所以MANAGER = CONSTANCE_CONFIG [‘ADMINS’] [0]完全错误(即使使用CONSTANCE_ADDITIONAL_FIELDS).您在此处访问常量值(非动态).
你需要像访问它一样
from constance import config
print(config.ADMINS)
3#默认日志记录配置使用admin_admins的AdminEmailHandler类,它使用来自django设置的ADMINS值,而不是constance配置.
因此,一种可能的解决方案可能是创建自己的处理程序类,该类将使用来自constance config的ADMINS值.所以将你的setting.py改为
CONSTANCE_CONFIG = {
'ADMIN1': ('admin@gmail.com', 'This one will receive error on 500'),
} # you can add as many admins as you want with ADMIN1, ADMIN2 etc(no tuple)
然后创建自己的处理程序类,它将使用CONSTANCE_CONFIG.
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)
然后更改您的LOGGER配置.如果您没有自定义LOGGING设置,我建议您从django.utils.log(DEFAULT_LOGGING)复制默认记录器配置.并将mail_admins更改为
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'], # change it to require_debug_true if you want to test it locally.
'class': '..ConstanceEmailHandler', # path to newly created handler class
'include_html': True
},