问题
I'm using Jinja2 on a new project, but would like to use the django-socialregistration app, which relies on Django template tags. Jinja2 doesn't play nicely with template tags, so I'm wondering if there's a quick workaround?
Template tags:
{% load facebook_tags %}
{% facebook_button %}
{% facebook_js %}
This previous question addresses the same topic for Mako, but I'm having trouble adapting it to work with Jinja2. The following is my attempt at an adaptation (non-working):
{% from django.template import Template, Context %}
{% tpl = "{% load facebook_tags %}{% facebook_button %}{% facebook_js %}" %}
${Template(tpl).render(Context(dict_=dict(request=request)))}
Any advice? I'm new to inlining, so don't know if the above is even close.
回答1:
Should the last line not just be:
{% Template(tpl).render(Context(dict=dict(request=request))) %}
来源:https://stackoverflow.com/questions/4799715/jinja2-templates-using-django-template-tags