经过几个小时的拔毛,我期待stackoverflow来帮助我解决这个问题。
我创建了两个信号来运行自动电子邮件功能。通过修改admin.py文件中的save_model来触发信号。
唯一的问题是......当通过Django开发服务器(发送自动电子邮件)时,信号同时工作,但在远程服务器上进行测试时,只有一个信号有效。我不明白这是怎么可能的,我也找不到这个错误。
我知道这里没有太多信息可以使用。对于这里可能发生的事情的任何建议?
对于文件/目录结构,这些信号保存在位于此特定应用程序目录中的signals.py文件中。通过修改admin.py文件中的save_model定义,在同一目录中触发该信号。
以下是信号定义:
notify_status_change_signal = Signal(providing_args=['status', 'restaurant', 'delivery_date', 'contact_email', 'contact_phone'])
notify_on_change_signal = Signal(providing_args=['organization', 'identifier', 'id', 'restaurant', 'delivery_date'])
@receiver(notify_on_change_signal)
def notify_on_change(sender, organization, identifier, id, restaurant, delivery_date, signal, *args, **kwargs):
"This is the signal that only functions when run through the local development server"
order_id = identifier + str(id)
subject = r'A change has been made to order %s' % order_id
body = """
System Message: The details for order %s (%s) have been updated by the client.""" % (order_id, organization)
send_mail(subject, body, 'System Notification <system@expressdelivery.com>', [admin_email], fail_silently=False)
@receiver(notify_status_change_signal)
def notify_status_change(sender, status, restaurant, delivery_date, contact_email, contact_phone, signal, *args, **kwargs):
"""This is the signal that works on both servers"""
stat_body = {
'Confirmed':"""
Message 1 """,
'Placed': """
Message 2 """,
'En Route': """
Message 3 """,
'Completed':"""
Message 4 """,
}
#Auto email
from_addr = 'Order Status <status@expressdelivery.com>'
to_addrs = [contact_email]
subject = u'Order %s %s status changed to %s.' % (restaurant, delivery_date, status)
body = ''
for stat_label, description in stat_body.iteritems():
if status == stat_label: body = description
if status == "Confirmed" or status == "En Route" or status == "Completed":
send_mail(subject, body, from_addr, to_addrs, fail_silently=False)
#Auto text message
if status == 'En Route':
client = TwilioRestClient(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
message = client.sms.messages.create(to=contact_phone,
from_="5555555555",
body="Your order, %s %s, is now en route." % (restaurant, delivery_date))
答案 0 :(得分:0)
虽然我在使用这些信号更新代码时确实重新启动了服务器,但重新启动服务器再次成功了。