繁体   English   中英

如果我进行自定义管道,则Django和Python-Social-Auth重定向

[英]Django and Python-Social-Auth redirect if I make custom pipeline

这是我的项目的目录:

/handshakeapp:
    templates/
    __init__.py
    admin.py
    models.py
    pipelines.py
    views.py
/VKHandshake:
    __init__.py
    settings.py
    urls.py
    ...
manage.py

这是settings.py一部分

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.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
    'handshakeapp.pipelines.fill_extendeduser'
)

这是handshakeapp/pipelines.py

from models import ExtendedUser

def fill_extendeduser(strategy, details, user=None, is_new=False, *args, **kwargs):
    if user and is_new:
        user.extendeduser_set.create(user=user.get_username(), countingID=None, profilePic='http://localhost:8000/pic.png')

但是,每次我尝试使用社交身份验证登录时,它都会重定向到/accounts/login/ 如果我从SOCIAL_AUTH_PIPELINE中删除了'handshakeapp.pipelines.fill_extendeduser' ,它'handshakeapp.pipelines.fill_extendeduser'起作用。 怎么了?

问题出在fill_extendeduser函数中。 如@omab所述,它引发了一个异常,并且:

Django auth进程将吃掉异常并重定向到LOGIN_URL的值,默认情况下为/ accounts / login /。 因此,在代码周围添加一个try / except块,以检查是否引发任何错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM