【问题标题】:how to display image from google account: django-allauth如何显示来自谷歌帐户的图像:django-allauth
【发布时间】:2015-06-12 18:36:46
【问题描述】:

我正在使用 django-allauth 通过 facebook 和 google 在我的应用程序中进行用户注册。我可以显示用户的 facebook 图像。但我不知道如何为谷歌做这件事。对于 facebook,我已经按照本教程进行操作 http://www.sarahhagstrom.com/2013/09/the-missing-django-allauth-tutorial/

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

【问题讨论】:

    标签: python django django-allauth


    【解决方案1】:

    这里提到How to populate user profile with django-allauth provider information?

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

    user.socialaccount_set.filter(provider='google')[0].extra_data['picture']
    

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

    <img src="{{ user.socialaccount_set.all.0.get_avatar_url }}" />
    

    【讨论】:

    • 如果用户没有设置图片,会返回None还是默认图片URL?
    猜你喜欢
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    相关资源
    最近更新 更多