The general method for converting a django templatetag to a jinja function is:
- create a function that's equivalent to the django templatetag (e.g., provider_login_url)
- add the function to the jinja Environment that you configured as the jinja environment in your django settings, usually in an
env.globals.update
call - see https://stackoverflow.com/a/41283502/93370 for more details
The above answer from Basalex used to work great but django-allauth>=0.55.0
removed providers.registry.by_id
so it won't work anymore if you upgrade django-allauth past that version.
I'm still looking for the "right" way to handle this but following django-allauth's provider_login_url implementation it seems you can do something like:
from allauth.socialaccount.adapter import get_adapter
def provider_login_url(request, provider_id, **kwargs):
provider = get_adapter(request).get_provider(request, provider_id)
... # logic to clean up next, auth_params etc.
return provider.get_login_url(request, **kwargs)
it also seems like you can look it up via the allauth.socialaccount.models.SocialApp
model
from allauth.socialaccount.models import SocialApp
def provider_login_url(request, provider_id, **kwargs):
provider = SocialApp.objects.get(provider=provider_id).get_provider(request)
... # logic to clean up next, auth_params etc.
return provider.get_login_url(request, **kwargs)