Making Django ignore string literals
Posted
by
James
on Stack Overflow
See other posts from Stack Overflow
or by James
Published on 2010-12-29T00:15:54Z
Indexed on
2010/12/29
0:53 UTC
Read the original article
Hit count: 209
django
|string-literals
UPDATE: It turns out this is a deeper question than I thought at first glance - the issue is that python is replacing the string literals before they ever get to django. I will do more investigating and update this if I find a solution.
I'm using django to work with LaTeX templates for report generation, and am running into a lot of problems with the way Django replaces parts of strings.
Specficially, I've run into two problems where I try to insert a variable containing latex code.
The first was that it would replace HTML characters, such as the less than symbol, with their HTML codes, which are of course gibberish to a LaTeX interpreter. I fixed this by setting the context to never autoescape, like so:
c = Context(inputs)
c.autoescape = False
However, I still have my second issue, which is that Django replaces string literals with their corresponding characers, so a double backslash becomes \, and \b becomes a backspace. How can I force Django to leave these characters in place, so
inputs['variable'] = '{\bf this is code} \\'
won't get mangled when I use
{{variable}}
to reference it in the django template?
© Stack Overflow or respective owner