2017-07-31 12 views
0

私はcreate_user_profileシグナルを持っています。私は同じシグナルを使ってユーザーにウェルカムメールを送信したいと思います。これは、このエラーで失敗しているDjangoは、ユーザーが信号を使って作成した後にウェルカムメールを送信します。

@receiver(post_save, sender=User) 
def update_user_profile(sender, instance, created, **kwargs): 
    if created: 
     UserProfile.objects.create(user=instance) 
    instance.profile.save() 

    subject = 'Welcome to MyApp!' 
    from_email = '[email protected]' 
    to = instance.email 
    plaintext = get_template('email/welcome.txt') 
    html = get_template('email/welcome.html') 

    d = Context({'username': instance.username}) 

    text_content = plaintext.render(d) 
    html_content = html.render(d) 

    try: 
     msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) 
     msg.attach_alternative(html_content, "text/html") 
     msg.send() 
    except BadHeaderError: 
     return HttpResponse('Invalid header found.') 

TypeError at /signup/ 
context must be a dict rather than Context. 

私の見解でforms.saveを指す

は、これは私がこれまでのところ、私のsignals.pyで書いたものです。 pyファイル。 ここに何が間違っているのか理解できますか?

答えて

1

ちょうどだけで正常に動作Contextオブジェクト

d = {'username': instance.username} 
text_content = plaintext.render(d) 
関連する問題