Mako templates using Django template tags

半城伤御伤魂 提交于 2019-11-28 01:10:52

问题


Our Django site is built using Mako templates. We want to use a third party project called django-socialregistration, but its template tags use Django's templates. If we used Django templates we could just

{% load facebook_tags %}
{% facebook_button %}
{% facebook_js %}

How can I do the same thing in Mako? You can inline strait up python in Mako, but I haven't figured out how to do it that way either.

Final Fix

<%! from django.template import Template, Context %>
<% tpl = "{% load facebook_tags %}{% facebook_button %}{% facebook_js %}" %>
${Template(tpl).render(Context(dict_=dict(request=request)))}

回答1:


I've hardly used Mako, but if you can include arbitrary Python code, you could always inline the template rendering function there.

<%
    tpl = """{% load facebook_tags %}{% facebook_button %}{% facebook_js %}"""
    from django.template import Template, Context
    t = Template(tpl)
    t.render(Context())
%>


来源:https://stackoverflow.com/questions/3790854/mako-templates-using-django-template-tags

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