开发者

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, &nbsp;, however, Django escapes the &, and it just shows up on the screen as &nbsp;. 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'''
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜