【问题标题】:django python social auth send emaildjango python social auth 发送电子邮件
【发布时间】:2015-09-28 06:48:36
【问题描述】:

我正在使用 python social auth 进行登录。创建用户后,我想向用户发送电子邮件。为此,我正在编写一个自定义管道

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 适用于其他电子邮件发送功能。

需要建议。谢谢

【问题讨论】:

    标签: django python-social-auth


    【解决方案1】:

    JSON 只接受几种数据类型:null、数组、布尔值、数字、字符串和对象。

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

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

    要解决这个问题,只发送需要的参数,而不是整个**kwargs

    我会创建一个字典并在其中包含所有内容:

    var args = dict()
    
    args['username'] = username
    args['template'] = template
    # other arguments
    
    notification_email.delay(args)
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 2015-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-09
      相关资源
      最近更新 更多