加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

django – python-social-auth部分管道无法恢复

发布时间:2020-12-16 23:17:33 所属栏目:Python 来源:网络整理
导读:我正在尝试使用 python-social-auth的部分管道为新用户收集密码.由于某些未知原因,我无法恢复管道,在提交表单后页面呈现回密码收集页面. 有线的是,即使我输入了http … / complete / backend-name,页面也会重定向回密码集合页面.看起来渲染进入无限循环,密码
我正在尝试使用 python-social-auth的部分管道为新用户收集密码.由于某些未知原因,我无法恢复管道,在提交表单后页面呈现回密码收集页面.

有线的是,即使我输入了http … / complete / backend-name,页面也会重定向回密码集合页面.看起来渲染进入无限循环,密码收集页面首先指向完整页面,完整页面直接返回密码收集页面.我检查了REDIRECT_FIELD_NAME的值,它是“下一步”.

我不确定我的代码有什么问题,非常感谢任何提示/建议.

settings.py

SOCIAL_AUTH_PIPELINE = (
    ...
    'accounts.pipeline.get_password',...
)

pipeline.py

from django.shortcuts import redirect
from social.pipeline.partial import partial

@partial
def get_password(strategy,details,user=None,is_new=False,*args,**kwargs):
    if is_new:
        return redirect('accounts_signup_social')
    else:
        return

views.py

def get_password(request):
    if request.method == 'POST':
        request.session['password'] = request.POST.get('password')
        backend = request.session['partial_pipeline']['backend']
        return redirect('social:complete',backend=backend)
    return render_to_response('accounts/social_signup.html',{"form":SocialSignUpForm},RequestContext(request))

解决方法

好.我发现了问题和解决方案.

正如文档所说,“管道将恢复与削减流程相同的功能.”在http://python-social-auth.readthedocs.org/en/latest/pipeline.html.这意味着它将始终渲染回相同的功能.

解决方案是在管道中添加密码的会话检查.如果密码存档,则返回下一个管道:

管道:

from django.shortcuts import redirect
from social.pipeline.partial import partial

@partial
def get_password(strategy,**kwargs):
    if is_new:
        if 'password' in kwargs['request'].session:
            return {'password': kwargs['request'].session['psssword']}
        else:
            return redirect('accounts_signup_social')
    else:
        return

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读