Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mako templates using Django template tags

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)))}
like image 804
Dave Aaron Smith Avatar asked Sep 24 '10 20:09

Dave Aaron Smith


People also ask

What are Django template tags?

Django Code The template tags are a way of telling Django that here comes something else than plain HTML. The template tags allows us to to do some programming on the server before sending HTML to the client.

Can I use Django template tags in Javascript?

You can't use Django's template tags from your Javascript code if that's what you mean. All the Django variables and logic stop existing after the template has been rendered and the HttpResponse has been sent to the client.

What does the built in Django template tag Lorem do?

lorem. Displays random “lorem ipsum” Latin text. This is useful for providing sample data in templates. A number (or variable) containing the number of paragraphs or words to generate (default is 1).


1 Answers

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())
%>
like image 111
Daniel Roseman Avatar answered Sep 23 '22 23:09

Daniel Roseman