Outputting Tabs with Django
I'm trying to output lines from a .cpp file to a template in Django开发者_Go百科. I pass the lines in a tuple called file
, and output it one line at a time.
{% for line in file %}
{{line}}<br />
{% endfor %}
Everything is very nicely autoescaped in the line, so that it is displayed correctly (like < and "), except for the \t characters. How can I make it print these so that they show up as tabs?
I tried replacing the tabs with a few escaped space characters,
, however, Django escapes the &, and it just shows up on the screen as
. I don't really want to turn of auto-escape, because it escapes everything else so nicely.
Is there an easy way for me to get these tab characters to show up correctly in this case?
Use u'\xa0'
instead.
u'''def foo():
\xa0\xa0return 42'''
精彩评论