【发布时间】:2016-11-05 00:22:08
【问题描述】:
我正在尝试从我的模板中获取会话社交变量。 我有 2 个单独的按钮用于注册和登录,使用密钥 login_type:
<a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}?login_type=1"><img src='img.png'> </a>
<a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}?login_type=2"><img src='img2.png'></a>
在我的设置中:
SOCIAL_AUTH_FIELDS_STORED_IN_SESSION = ['login_type']
我也试过:
FIELDS_STORED_IN_SESSION = ['login_type']
我的自定义管道:
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',
'FBAuth.facebook.check_if_exists',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
)
facebook.py:
from django.conf import settings
from django.shortcuts import redirect, HttpResponse
def check_if_exists(strategy, request, *args, **kwargs):
login_type = strategy.request.GET.get('login_type')
#login_type = strategy.session_get('key') (I tried all cases)
#login_type = request['login_type']
#login_type = strategy.request['login_type']
logger.debug("is_new parameter is %s", kwargs['is_new'])
logger.debug("login_type is %s", login_type)
if kwargs['is_new']:
if login_type == 1:
return redirect('/', message ='Specified social account is not yet associate with any existent user, try to Sign up first')
else:
if login_type == 2:
return redirect('/', message = 'User for this account is already exist, try to login')
return None
但是,无论如何,在我的日志中,我总是看到“login_type is None”
怎么了?
【问题讨论】: