django-signal实例到电子邮件发送属性编码

时间:2013-09-11 16:55:37

标签: django django-signals django-email

美好的一天。带信号的模型必须发送到电子邮件实例,但是我在代码块之后放置了追溯

class ParticipantModel(models.Model):

TYPE_USER = (
    ('O', 'Онлайн трансляция'),
    ('P', 'Персональное присутствие'),
)
name = models.CharField( max_length=256, verbose_name='Имя')
surname = models.CharField(max_length=50, verbose_name='Фамилия')
position = models.CharField(max_length=50, verbose_name='Должность')
company = models.CharField(max_length=50, verbose_name='Название компании')
city = models.CharField(max_length=50, verbose_name='Город')
email = models.EmailField(verbose_name='Электро почта')
phone = models.CharField(max_length="50", verbose_name="Телефон")
phonem = models.CharField(max_length="50", verbose_name="Мобильный телефон")
www = models.URLField(verbose_name="Сайт")
tuser = models.CharField(max_length='250', choices=TYPE_USER, verbose_name="Форма вашего участия")
class Meta:
    verbose_name = ('Участник')
    verbose_name_plural = ('Участники')

def send_marketing(self, sender, instance, created, **kwargs):
if created:
    message = instance
    subject = "McAfee day"
    from_email = 'bakotech.events@gmail.com'
    recipient_list = ('sergey@avetisyan.com.ua', 'marketing@bakotech.com')
    send_mail(subject, message, from_email, recipient_list)
post_save.connect(send_marketing, sender=ParticipantModel)

回溯:

/ reg的AttributeError 'ParticipantModel'对象没有属性'encode' 请求方法:POST 请求网址:
Django版本:1.5.2 异常类型:AttributeError 例外价值:
'ParticipantModel'对象没有属性'encode' 异常位置:/usr/lib/python2.7/email/encoders.py in encode_7or8bit,第73行 Python可执行文件:/ usr / bin / uwsgi-core Python版本:2.7.3 Python路径:
[ '',  ',  '/home/sergey/djprojects/venvs/bakoevents/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg',  '/home/sergey/djprojects/venvs/bakoevents/local/lib/python2.7/site-packages/distribute-0.7.3-py2.7.egg',  '/home/sergey/djprojects/venvs/bakoevents/local/lib/python2.7/site-packages/setuptools-1.1-py2.7.egg',  '/home/sergey/djprojects/venvs/bakoevents/lib/python2.7/site-packages/pip-1.1-py2.7.egg',  '/home/sergey/djprojects/venvs/bakoevents/lib/python2.7/site-packages/distribute-0.7.3-py2.7.egg',  '/home/sergey/djprojects/venvs/bakoevents/lib/python2.7/site-packages/setuptools-1.1-py2.7.egg',  '/home/sergey/djprojects/venvs/bakoevents/lib/python2.7',  '/home/sergey/djprojects/venvs/bakoevents/lib/python2.7/plat-linux2',  '/home/sergey/djprojects/venvs/bakoevents/lib/python2.7/lib-tk',  '/home/sergey/djprojects/venvs/bakoevents/lib/python2.7/lib-old',  '/home/sergey/djprojects/venvs/bakoevents/lib/python2.7/lib-dynload',  '/usr/lib/python2.7',  '/usr/lib/python2.7/plat-linux2',  '/usr/lib/python2.7/lib-tk',  '/home/sergey/djprojects/venvs/bakoevents/local/lib/python2.7/site-packages',  '/home/sergey/djprojects/venvs/bakoevents/local/lib/python2.7/site-packages/PIL',  '/home/sergey/djprojects/venvs/bakoevents/lib/python2.7/site-packages',  '/home/sergey/djprojects/venvs/bakoevents/lib/python2.7/site-packages/PIL'] 服务器时间:Срд,11Сен201319:49:00 +0300

1 个答案:

答案 0 :(得分:0)

您将实例传递到电子邮件类所需的字符串:

message = instance
...
send_mail(subject, message, from_email, recipient_list)

您需要使用字符串。