简体   繁体   English

Django Allauth-int()参数必须是字符串或数字,而不是'ReverseSingleRelatedObjectDescriptor'

[英]Django Allauth - int() argument must be a string or a number, not 'ReverseSingleRelatedObjectDescriptor'

I am trying to get the user from a model into a view, however I keep getting a type error: 我试图使用户从模型进入视图,但是我不断收到类型错误:

Type error - int() argument must be a string or a number, not 'ReverseSingleRelatedObjectDescriptor' 类型错误-int()参数必须是字符串或数字,而不是'ReverseSingleRelatedObjectDescriptor'

When I get to the user I have the following: django.db.models.fields.related.ReverseSingleRelatedObjectDescriptor object at 0x7f4a15299590 当我找到用户时,我有以下内容:django.db.models.fields.related.ReverseSingleRelatedObjectDescriptor对象位于0x7f4a15299590

Models.py 型号

@python_2_unicode_compatible
class SocialAccount(models.Model):
    user = models.ForeignKey(allauth.app_settings.USER_MODEL)
    provider = models.CharField(verbose_name=_('provider'),
                                max_length=30,
                                choices=providers.registry.as_choices())

    uid = models.CharField(verbose_name=_('uid'),
                          max_length=app_settings.UID_MAX_LENGTH)
    last_login = models.DateTimeField(verbose_name=_('last login'),
                                      auto_now=True)
    date_joined = models.DateTimeField(verbose_name=_('date joined'),
                                   auto_now_add=True)
    extra_data = JSONField(verbose_name=_('extra data'), default='{}')

    class Meta:
        unique_together = ('provider', 'uid')
        verbose_name = _('social account')
        verbose_name_plural = _('social accounts')

    def authenticate(self):
        return authenticate(account=self)

    def __str__(self):
        return force_text(self.user)

Views.py Views.py

from allauth.socialaccount.models import SocialToken, SocialAccount
def sc(request):
   user = SocialAccount.user
   token = SocialToken.objects.filter(account__user=user, account__provider='soundcloud')

In your view, SocialAccount is the model itself, not a particular instance of it. 您认为,SocialAccount是模型本身,而不是模型的特定实例。 You would need to actually query for the account you want, like you do with the token. 您实际上需要查询所需的帐户,就像使用令牌一样。

But I'm not sure why you are doing anything with SocialAccount in the first place. 但是我不确定为什么首先要使用SocialAccount做任何事情。 You actually want the user, which is presumably just request.user ; 您实际上想要的是用户,大概就是request.user use that instead. 用它代替。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 django - int参数必须是字符串或数字,而不是'元组' - django - int argument must be a string or a number, not 'Tuple' Django int()参数必须是字符串或数字 - Django int() argument must be a string or a number int()参数必须是字符串或数字,而不是django中的'SimpleLazyObject' - int() argument must be a string or a number, not 'SimpleLazyObject' in django Django:int()参数必须是字符串或数字,而不是'Plain' - Django : int() argument must be a string or a number, not 'Plain' int() 参数必须是字符串或数字 - int() argument must be a string or a number Django-TypeError:int()参数必须是字符串或数字,而不是'dict' - Django - TypeError: int() argument must be a string or a number, not 'dict' 在django模型中保存datetimefiled,int()参数必须是字符串或数字 - saving datetimefiled in django models, int() argument must be a string or a number Django TypeError int()参数必须是字符串或数字,而不是'QueryDict' - Django TypeError int() argument must be a string or a number, not 'QueryDict' Django保存新记录,int()参数必须是字符串或数字,而不是'QueryDict' - Django Saving new record, int() argument must be a string or a number, not 'QueryDict' Django错误:TypeError:int()参数必须是字符串或数字,而不是“ BuildsTable” - Django Error: TypeError: int() argument must be a string or a number, not 'BuildsTable'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM