如何显示来自谷歌帐户的图像:django-allauth

Roh*_*hit 5 python django django-allauth

我正在通过 facebook 和 google 在我的应用程序中使用 django-allauth 进行用户注册。我可以显示用户的 Facebook 图像。但我不知道如何为谷歌做到这一点。对于Facebook,我遵循了本教程http://www.sarahagstrom.com/2013/09/the-missing-django-allauth-tutorial/

有人可以建议我如何在我的网站中显示用户的谷歌帐户图像。

Amr*_*ziz 8

正如这里提到的How to populate user profile with django-allauthprovider information? :

在您的服务器端代码中您可以尝试

user.socialaccount_set.filter(provider='google')[0].extra_data['picture']
Run Code Online (Sandbox Code Playgroud)

在模板中你可以这样得到它

<img src="{{ user.socialaccount_set.all.0.get_avatar_url }}" />
Run Code Online (Sandbox Code Playgroud)

  • 如果用户没有设置图片,会返回“None”或默认图片 URL 吗? (3认同)