Z
Z
zigen2015-12-22 14:28:27
Django
zigen, 2015-12-22 14:28:27

How to get avatar url in python-social-auth?

Good afternoon.
I made a custom pipline to save avatars of users who log in through social networks.
For example:

def save_profile(backend, user, response, *args, **kwargs):
    if isinstance(backend, VKOAuth2):
        if not user.avatar:
            url = response['photo']
            try:
                response = request('GET', url)
                response.raise_for_status()
            except ConnectionError:
                pass
            else:
                user.avatar.save(u'',
                                 ContentFile(response.content),
                                 save=False
                                 )
                user.save()

How to make it so that the avatar is not saved, but stupidly give the URL to it in the template?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question