我正在为法语应用程序编写定制Django模板标记。我的模板标签需要一个参数是一个字符串:模板标记值中的Django非ASCII字符
{% mytag "Hello" %}
是完美的作品,而是试图把一些非ASCII字符的值时失败。
你将如何让这件事的工作:
{% mytag "Êtes-vous à Paris ?" %}
我得到这个错误:
'ascii' codec can't encode character u'\xca' in position 0: ordinal not in range(128)
Unicode error hint
The string that could not be encoded/decoded was: Êtes-v
提前感谢非常感谢!
编辑: Python版本是2.7。下面是标签的代码:
@register.simple_tag(takes_context=True)
def mytag(context, my_var):
return "Here it is: {my_var}".format(my_var=my_var)
哪个python版本?你能告诉我们标签的代码吗? – Wtower
看看是否有帮助http://stackoverflow.com/a/13986802/2445183 – itzhaki
Python版本是2.7。在初始文章中添加标签代码。感谢您的帮助... – user650108