Display Django code from a Django template

I am trying to display the Django source code from a Django template. However, I cannot find a tag that looks like HTML pre or xmp.

Here code

In addition, I have a block with the same name that causes the error.

+1
source share
4 answers

If your view puts the source code in a context variable called source, your template might look like this:

<pre>
{{ source|escape }}
</pre>

The escape filter will escape from certain characters to make sure that the HTML is displayed correctly.

If you just want to display the source of the encoded template in your template, there are two options.

Use HTML escaping to do this and remove the XMP tags.

&#123; instead of }
&#125; instead of {

templatetag:

{% templatetag openbrace %} instead of }
{% templatetag closebrace %} instead of {

.. .

+5

, : django, '{' '}'

&#123; and &#125;

django var.

: django :) http://docs.djangoproject.com/en/dev/ref/templates/builtins/#templatetag p >

+1

Django .

+1

verbatim

{% verbatim %} 
...
{% endverbatim %}
0

Source: https://habr.com/ru/post/1719190/


All Articles