I want to display a picture of the current_user in my template. How can I access the user's facebook id when I'm using django-allauth?
For each user that is signed up via a social account a SocialAccount
instance is available. This model has a foreign key to User
. Note that a user can connect multiple social networking accounts to his local account, so in practice there may be more than one SocialAccount
instances available.
How you want to deal with this is project dependent. I can imagine one would want to copy the profile image locally, or perhaps you would want to give preference to the Google+ profile picture above the Facebook one, and so on.
The SocialAccount
model has some helper methods that give you access to account basics such as the profile picture. All in all, this is a quick & dirty way to access first available profile picture:
{{user.socialaccount_set.all.0.get_avatar_url}}
The ID is also available:
{{user.socialaccount_set.all.0.uid}}
See also: https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/models.py#L72
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With