[Django]-How can I display a meaningful login error messages to user within python-social-auth?

2👍

Take a look at the middleware from the django_app:

https://github.com/omab/python-social-auth/blob/526439ac66b00ce801e4fc5df89633a66eb8ffb2/social/apps/django_app/middleware.py

and either create your own based on this or extended by overriding. As mentioned there, probably the get_message method.

👤Rush

1👍

to handle this, I do the following:

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',
    # the custom pipeline step
    'accounts.views.user_details_after',
)
...

views.py

def user_details_after(strategy, details, user=None, *args, **kwargs):
    if not user:
        messages.info(strategy.request, "You have to sign up first.")

in the loging template I render the message to display it to the user.

👤udo

0👍

A simpler way is to just render the error page with the info you want, like

return render(
        request,
        "error.html",
        {
        "error_title":"Custom Error",
        "error_message":"This is an error"
        }
    )

and your templates/error.html template

<h1>{{ error_title }}</h1>
<p>{{ error_message }}</p>

Leave a comment