【发布时间】:2014-11-11 19:40:49
【问题描述】:
上周有效。也许是我做错了什么并在其他地方搞砸了,或者它是一个错误,或者它只是一个更新,我在阅读文档时错过了它。
我有一个获取用户头像并保存 URL 的管道:
def get_avatar(strategy, details, response, user, *args, **kwargs):
url = None
if strategy.backend.name == 'facebook':
url = 'http://graph.facebook.com/{0}/picture'.format(response['id'])
elif strategy.backend.name == "twitter":
if response['profile_image_url'] != '':
url = response['profile_image_url']
elif strategy.backend.name == "google-oauth2":
if response['image'].get('url') is not None:
url = response['image'].get('url')
以前可以用,现在报错了:
'DjangoStrategy' object has no attribute 'backend'
请帮忙,一些测试版用户已经在使用我的网站,但目前他们没有个人资料图片。
【问题讨论】:
-
你项目中的 DjangoStrategy 是什么?是模特吗?
-
没有。 Django Strategy 是 Python Social Auth 使用的对象。
-
您是否将
python-social-auth更新到版本0.2.2?如果是这种情况,那么您需要更新您的管道,只需删除strategy.backend用法,并将backend参数添加到函数并使用该参数。 -
不,我使用的是 python-social-auth 0.2.1。这很奇怪,因为昨天我做了
pip-review --auto更新了所有的包。无论如何,我使用kwargs['backend'].redirect_uri解决了这个问题并在那里检查后端名称。我不确定这是否是最好的方法,但它确实有效。 -
我的评论仍然适用,
backend参数是在版本0.2.0中添加的。
标签: python django python-social-auth