daveslab
daveslab

Reputation: 10310

How to exclude a part of a Django template file from processing?

I have a Django template file that has a couple of enormous strings in it (images encoded in Base64). When I use the Django templating engine, it chokes and takes 5 minutes to render the template. Is there a way to exclude a part of a template, with something like:

{% ignore %}
  <img src='....'>
{% endignore %}

Does this exist?

Upvotes: 2

Views: 3293

Answers (1)

ndpu
ndpu

Reputation: 22571

Use verbatim tag!

From django docs https://docs.djangoproject.com/en/dev/ref/templates/builtins/#verbatim

verbatim

Stops the template engine from rendering the contents of this block tag.

A common use is to allow a JavaScript template layer that collides with Django’s syntax. For example:

{% verbatim %}
    {{if dying}}Still alive.{{/if}}
{% endverbatim %}

Upvotes: 5

Related Questions