我正在尝试使用
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