应用程序无法使用 Django AllAuth 访问个人资料图片和帖子

Application not able to access the profile pic and posts using DjangoAllAuth

我正在尝试使用 Django-AllAuth 访问用户的个人资料图片和帖子。这是我尝试加载个人资料图片的模板:

<html>


<body>

 Welcome back {{ user.first_name }} {{ user.age }}
 <img src={{user.cover.source}} height="60" width="60">

<a href="/">Home</a>
</body>


</html>

这里是 view.py

def fb_personality_traits(request):
    # logger.debug('FB Page Loaded')
    return render(request, 'home/facebook_personality_traits.html')

Settings.py

SITE_ID = 1

LOGIN_REDIRECT_URL = '/facebook_personality_traits/'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
    'facebook': {
        'SCOPE': ['email', 'user_posts', 'public_profile', 'user_photos'],
        # 'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
        'METHOD': 'js_sdk',
        'FIELDS': [
            'id',
            'email',
            'name',
            'first_name',
            'last_name',
            'cover',
            'posts',
            'age',
        ],
        'EXCHANGE_TOKEN': True,
        'VERIFIED_EMAIL': True,
        'VERSION': 'v2.10',
    }
}
ACCOUNT_LOGOUT_ON_GET = True

这里我没有得到图像。查看以下结果:

我想达到什么目的?

1) 我想在屏幕上显示头像。

2) 我想获取在 view.py 中登录的用户的帖子,并将其发送到屏幕上以显示在模板上。

django-allauth 不会保留 agecover 等非必要字段。只有公共字段会自动保留在 User 模型中 (see fields). You would need to handle this yourself, by capturing the data and storing it somewhere, like your database. These fields are only retrieved and accessible on the post-login response (see example method),它们可以在 extra_data 字典中找到。

我建议在成功登录后在 SocialAccount 实例(在本例中为 Facebook)上调用 get_avatar_url 并将此值存储在您的数据库中。就 Facebook 而言,用户头像 URL 不应随时间改变。