django python社交身份验证发送电子邮件

问题描述:

我正在使用python社交身份验证登录。用户创建后,我想向用户发送一封电子邮件。为此,我正在写一个自定义管道django python社交身份验证发送电子邮件

def send_confirmation_email(strategy, details, response, user=None, *args, **kwargs): 
if user: 
    if kwargs['is_new']: 
     template = "email/social_registration_confirm.html" 
     subject = "Account Confirmation" 
     email = user.email 
     print(user.username) 
     username = user.username 
     kwargs.update(subject=subject, email=email, username=username) 
     notification_email.delay(template, **kwargs) 

我使用celery发送电子邮件。当我发送电子邮件时,它给我错误说<UserSocialAuth: some_username> is not JSON serializable

为什么我得到这个错误。 notification_email适用于其他电子邮件发送功能。

需要建议。谢谢

JSON只接受一些数据类型:null,数组,布尔值,数字,字符串和对象。

所以,其他任何东西都应该表达为这些类型之一。

我的猜测是**kwargs您发送到notification_email包含的数据类型不能表示为JSON。

要解决此问题,请仅发送所需参数,而不是整个**kwargs

我想创建一个字典,包括那里的一切:

var args = dict() 

args['username'] = username 
args['template'] = template 
# other arguments 

notification_email.delay(args) 

我希望它能帮助。