I'm working on a website which uses Django templates, and I have to produce HTML which contains paired curly quotes. Is there any way to disable Django's tag processing for a block of code? Something like a literal block tag would be nice, so that:
{% literal %}
{% LITERAL {{ BRACES }}
{% endliteral %}
... would produce {% LITERAL {{ BRACES }} in the output.
For the record, this is possible now with the template tag verbatim.
EDIT: Your syntax is currently impossible with the current lexer / parser system.
Why? Basically the template system has a Lexer and a Parser. The Lexer takes the template string as input, and tokenizes it. The parser then takes the list of tokens in its constructor and parses them into a list of a bunch of Nodes for the compiled template. The template tags and filters only have access to the already constructed parser -- you can't access the initial lexer string. See the comments in django/templates/__init__.py
However, there is a solution. It's not mine (see below), but its to basically use server side includes {% ssi some_file.html %} to include an extra file that has the literal text. Yes this is an ugly solution; but without a major rewrite of the templating system it will have to suffice.
Easy Way to Escape Django Template Variables
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With