我在 django 中使用 format_html(..) 函数。当我使用特殊字符(如重音符号)时,它会失败。有没有办法将 format_html(..) 与特殊字符一起使用?
我找到的解决方案是:
format_html('<label>{0}</label>', smart_text(classes).encode('ascii', 'ignore'))
但它只删除特殊字符。
最佳答案
正确的解决方案是像 Django 所做的那样 from __future__ import unicode_literals
或者在 unicode
上调用 .format
而不是在 str 上
.
关于python - django format_html 不支持 unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26920017/