Handlebars.js in Django templates

前端 未结 8 1580

I need a javascript templating system and i think handlebars.js does an excellent job in this case. I\'m having syntax conflicts with handlebars templates inside a django te

8条回答
  •  滥情空心
    2020-12-24 06:44

    Is there a tag in django templates to stop rendering a block with curly braces?

    OLD Answer for Django 1.0-1.4: No, though you could though you could put the block in a separate file and include it without rendering or use a different templating engine.

    New Answer: The answer above was correct in August 2011 when the question was asked and answered. Starting in Django 1.5 (released Feb 2013, though alpha/beta versions in late 2012), they introduced the {% verbatim %} and {% endverbatim %} which will prevent the django template engine from processing the content in the block.

    So for the question asked the following will work in django 1.5+ out of the box:

    {{ django_context_varable }} #works
    {% verbatim %}
    
    {% endverbatim %}
    

    The documentation on verbatim is here. Yes, this was noted by others earlier, but as this is the accepted answer I should list the easiest solution.

提交回复
热议问题