Jinja2 templates using Django template tags

爷,独闯天下 提交于 2019-12-29 08:50:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!