【问题标题】:pipeline django social auth管道 django 社交身份验证
【发布时间】:2014-04-18 13:03:50
【问题描述】:

这是我使用 django 的第一个项目,我安装了 django social auth 并且工作正常,但是当我使用自定义管道时,注册会转到 /login-error

使用 python 2.6 django 1.6.2

#settings.py

SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
'social_auth.backends.pipeline.user.create_user',
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',
'social_auth.backends.pipeline.user.update_user_details',
'social_auth.backends.pipeline.misc.save_status_to_session',
'app.pipelines.get_user_avatar'
)


#pipelines.py

def get_user_avatar(strategy, user, response, is_new=False,*args,**kwargs):
url = None
if is_new and strategy.backend.name == 'facebook':
    url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
if url:
    profile = user.get_profile()
    profile.photo = url # depends on where you saved it
    profile.save()


#models.py

from django.db import models
from django.contrib.auth.models import User

class Profile(models.Model):
    user = models.ForeignKey(User)
    points = models.IntegerField(default = 0)
    photo = models.URLField()

【问题讨论】:

  • 你用的是什么版本的python和django? python --versiondjango-admin.py --version
  • 仅供参考,Django-social-auth 现在已弃用。谨慎使用。
  • 使用python 2.6 django 1.6.2

标签: django django-socialauth


【解决方案1】:

您需要改用python social auth。 Django 社交身份验证已被弃用。

【讨论】:

    【解决方案2】:

    您的代码中有几个细节不正确。

    1. 'social_auth.backends.pipeline.misc.save_status_to_session' 仅在您计划将用户重定向到另一个视图/表单时使用(中断处理并稍后继续)
    2. 您的自定义管道正在使用strategy,这是python-social-auth 中的一个参数,但不是django-social-auth

    既然您要开始,我建议您直接使用python-social-auth,因为django-social-auth is deprecated

    【讨论】:

    • 好吧,我实现了 python-social-auth 并按照你的建议修复了代码,但我有同样的问题
    • @LuisAlfredo,将管道设置更新为默认值psa.matiasaguirre.net/docs/…(您在顶部缺少一些条目),检查默认值是否有效,然后将您的管道功能添加到列表中并进行调试如果失败。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-03
    相关资源
    最近更新 更多