문제

Am using python social auth with django to create authentication and registration via social media. I've defined the

LOGIN_ERROR_URL = '/account/auth-failed/'

it works well when there is a problem, it would redirect there correctly. Yet, I want to conditionally specify the LOGIN_ERROR_PAGE at run time because I have a scneario where its invoked via JSON or simple HTML.

Any suggestion on how to do that?

도움이 되었습니까?

해결책

It's not really simple to implement, but you can override the default strategy and in your custom version override the get_setting() method, like this:

from django.conf import settings

from social.strategies.django_strategy import DjangoStrategy


class CustomDjangoStrategy(DjangoStrategy):
    def get_setting(self, name):
        if name == 'LOGIN_ERROR_URL' and self.request.is_ajax():
            return '/auth/error/ajax'
        else:
            return getattr(settings, name)

Put that into a module and define SOCIAL_AUTH_STRATEGY = app.module.CustomDjangoStrategy in your settings.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top