How to access user names and profiles with django-allauth

Richard picture Richard · Dec 12, 2011 · Viewed 9.1k times · Source

I'm using Django with django-allauth for social authentication.

I have authentication up and running, but can anyone give simple examples of how to:

  • show the name and avatar of a logged-in user
  • add some information to a user's account?

For example, on the home page, I've got

{% if user.is_authenticated %}
<li><a href="{% url account_logout %}?next=/">Logout</a></li>
{% endif %}

That's showing the Logout link correctly, but how would I add the user's name and avatar?

Something like (pseudocode):

<p>You're logged in with {{ user.account_provider? }} as {{ user }}.</p>
<img src="{{ user.avatar_url }}" />

Then, if I want to add extra properties to the user's profile, what do I do? Should I be using some other Django user-related app?

Thanks for your help.

Answer

lig picture lig · Dec 12, 2011

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 }}" />