python-3.x – Django allauth how to get the user token from which the session is opened in the browser?


Good morning.

You need to post a picture on the vk wall on behalf of the user who logged in to the site.

Tried getting his token like this.
social_accounts = SocialAccount.objects.filter(provider='vk')
for social_account in social_accounts:
    socialtokens = SocialToken.objects.filter(

But I am not given a token of the one who logged in to the site, but the first one registered through the social network, and plus gives this token for use even to those who are not authorized.

I sort of figured out the unauthorized ones. Probably not correct, but they can no longer perform the cherished action.

 if request.user.is_authenticated:
        return render(request, 'parsing/Page1.html', {'values': ['Hello']})
        return render(request, 'parsing/Page2.html', {'values': ['не Hello']})

But it is impossible to get the user token from which the session is open. Where can I find a solution? I did not find this in the documentation on the off site. On the forums, too, I did not google anything like that.

Python3.6 Django2.0


Well, it seems to me, first you need to find the correct account for the user from the session. Then, if this account exists, search for this account for its token.

social_account = SocialAccount.objects.filter(provider='vk',
socialtoken = SocialToken.objects.filter(

This is how it should work

social_account = SocialAccount.objects.get(provider='vk',
social_token = SocialToken.objects.get(account=social_account)
Scroll to Top