如何使用django-allauth访问用户名和配置文件 [英] How to access user names and profiles with django-allauth

查看:125
本文介绍了如何使用django-allauth访问用户名和配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有django-allauth的Django进行社交身份验证。

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:


  • 显示已登录用户的名称和头像

  • 是否向用户帐户添加了一些信息?

例如,在首页上,我有

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

然后,如果我想在用户的个人资料中添加其他属性,该怎么办?我应该使用其他与Django用户相关的应用吗?

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?

感谢您的帮助。

推荐答案

使用 SocialAccount 模型实例可供使用的用户注册他们的社交帐户。

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

在您的模板中,您只需编写:

In your template, you can simply write:

头像URL: {{user.socialaccount_set.all.0.get_avatar_url}}

UID: {{user.socialaccount_set.all.0.uid}}

加入日期: {{user.socialaccount_set。 all.0.date_joined}}

最后一次登录: {{user.socialaccount_set.all.0.last_login}}

对于全名: {{user.socialaccount_set.all.0。 extra_data.name}}

更多信息: Django allauth来源

这篇关于如何使用django-allauth访问用户名和配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆