I have the following string:
我有以下字符串:
teststring= "§"
When I print it in python within Django I keep getting a weird symbol. How do I make it so that it eliminates the conversion of a string to ASCII symbol and treats it as the literal string "§"
当我在Django中使用python打印它时,我总是得到一个奇怪的符号。如何使它消除将字符串转换为ASCII码并将其视为文字字符串"§"
2 个解决方案
#1
1
Your browser is interpreting the §
value as §
, the section character: §
您的浏览器解释教派的宗教价值;,部分字符:§
You need to escape the ampersand as &sect
to prevent this:
你需要逃离这个“人”和“门”,以防止出现这样的情况:
teststring = "&sect"
Django templates can do this escaping for you by using the escape filter, or you can use the cgi.escape()
function:
Django模板可以通过使用escape过滤器来实现这种转义,也可以使用cgi.escape()函数:
teststring = cgi.escape("§")
#2
1
Use django's escape filter in your template. Something like:
在模板中使用django的escape过滤器。喜欢的东西:
<b>check out my string: {{ teststring|escape }}</b>
Or turn autoescape on.
或打开autoescape。
#1
1
Your browser is interpreting the §
value as §
, the section character: §
您的浏览器解释教派的宗教价值;,部分字符:§
You need to escape the ampersand as &sect
to prevent this:
你需要逃离这个“人”和“门”,以防止出现这样的情况:
teststring = "&sect"
Django templates can do this escaping for you by using the escape filter, or you can use the cgi.escape()
function:
Django模板可以通过使用escape过滤器来实现这种转义,也可以使用cgi.escape()函数:
teststring = cgi.escape("§")
#2
1
Use django's escape filter in your template. Something like:
在模板中使用django的escape过滤器。喜欢的东西:
<b>check out my string: {{ teststring|escape }}</b>
Or turn autoescape on.
或打开autoescape。