1
votes

In huge efforts to move from Django Templates to Jinja2 I got into some issues. Unfortunately (surprisingly) I couldn't find much information on this.

The main issue is the tags:

<a class="ui twitter button" href="{% provider_login_url "twitter" method="oauth2" next="/photos/new" %}">

Jinja2 won't recognize it:

django.template.exceptions.TemplateSyntaxError: ("Encountered unknown tag 'provider_login_url'.

There must be someone out there who has managed to make this work. Isn't there an easy way to make the template tag available for jinja2 to use? What's the generic way to make a 3rd party library to work with jinja2?

1

1 Answers

0
votes

This is what I used (register as func for jinja2), not sure if it's 100% works as native tag, but I hadn`t had any issues yet.

def provider_login_url(request, provider_id, **kwargs):
    provider = providers.registry.by_id(provider_id) 
    query = kwargs
    if 'next' not in query:
       next_ = request.GET.get('next')
       if next_:
           query['next'] = next_
    else:
        if not query['next']:
           del query['next']
    return provider.get_login_url(request, **query)