Mako模板使用Django模板标签 [英] Mako templates using Django template tags
本文介绍了Mako模板使用Django模板标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们的Django网站是使用Mako模板构建的。我们要使用第三方项目 django-socialregistration ,但其模板标签使用Django的模板。如果我们使用Django模板,我们可以只是
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 %}
如何在Mako做同样的事情?你可以在马科线上加入蟒蛇,但是我还没有想到如何做到这一点。
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.
最终修正 p>
Final Fix
<%! from django.template import Template, Context %>
<% tpl = "{% load facebook_tags %}{% facebook_button %}{% facebook_js %}" %>
${Template(tpl).render(Context(dict_=dict(request=request)))}
推荐答案
我几乎没有使用过Mako,但是如果你可以包含任意的Python代码,你可以随时在其中嵌入模板渲染功能。
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())
%>
这篇关于Mako模板使用Django模板标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文