python-social-auth部分管道设置表单数据到会话

时间:2014-11-29 21:59:41

标签: django session serialization python-social-auth

我使用python-social-auth登录并创建用户个人资料。与在管道末尾创建配置文件的profile example here 不同,我的应用程序不允许在没有配置文件的情况下创建用户。我遵循github源代码中提供的Django example,所以我有一个部分管道,需要配置文件并在验证成功后显示Django表单。

SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'accounts.pipeline.require_profile',
'accounts.pipeline.create_user_profile',
'social.pipeline.social_auth.associate_user',
'social.pipeline.debug.debug',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
#'social.pipeline.debug.debug'

部分管道重定向到呈现登录和配置文件表单的视图。 以下是视图中的代码,用于检查表单是否有效,然后完成管道。

if profile_form.is_valid():
       request.session['form_data'] = profile_form.cleaned_data
       ...
       return redirect('social:complete', backend=backend)

表单包含CharFields和ModelMultipleChoiceField / ModelChoiceField的混合,当我尝试在会话中设置表单数据时,我得到了一个类型错误,因为dict不可序列化:

Type Error: <Model: object> is not JSON serializable.

当我读到它并尝试'django.contrib.sessions.serializers.PickleSerializer'时,它运行良好。但在阅读了它的性能和security issues.

后,我不愿意使用它

我是Python-social-auth的新手,这可能不是最好的方法。我想知道是否有办法将表单数据传递给管道,而无需编写自定义序列化程序,以便保存用户和配置文件。

感谢您的帮助。

修改

我如何处理这个问题是让配置文件表单提交重定向到管道(部分)而不是视图。在管道中,当请求是POST并验证表单时,我使用了request_data,并在详细信息dict中设置了配置文件表单数据。可能不是最好的解决方案,但它为我完成了工作)

0 个答案:

没有答案