How to access user names and profiles with django-allauth

拥有回忆 提交于 2019-11-30 07:18:34

If you look at django-allauth source https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/models.py#L7

This is an abstract model that represents all the methods all other specific service models have. Thus you could write

<p>You're logged in with {{ user.get_provider }} as {{ user }}.</p>
<img src="{{ user.get_avatar_url }}" />

A SocialAccount model instance is available for users who signed up using their social account.

In your template, you can simply write:

Avatar URL: {{ user.socialaccount_set.all.0.get_avatar_url }}
UID: {{ user.socialaccount_set.all.0.uid }}
Date Joined: {{ user.socialaccount_set.all.0.date_joined}}
Last Login: {{ user.socialaccount_set.all.0.last_login}}

And for Full Name: {{ user.socialaccount_set.all.0.extra_data.name }}

For more information: Django allauth source

you can make for loop in set of socialaccount within foreignkey to user class, in the template it's something like below :

{% for account in user.socialaccount_set.all %}

 {% comment %} show avatar from url {% endcomment %}
 <h2 style="text-transform:capitalize;">{{ account.provider }} account data</h2>

 <p><img width="50" height="50" src="{{ account.get_avatar_url }}"/></p>

 <p>UID: <a href="{{ account.extra_data.link }}">{{ account.uid }}</a></p>

 <p>Username: {{ account.extra_data.username }}</p>

  <p>First Name: {{ account.extra_data.first_name }}</p>

  <p>Last Name: {{ account.extra_data.last_name }}</p>

  <p>Dashboard Link: 
  <a href="{{ account.extra_data.link }}">{{ account.extra_data.link }}</a></p>
  {% empty %}
  <p>you haven't any social account please</p>
{% endfor %}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!