开发者

django utf-8 normalization

开发者 https://www.devze.com 2023-01-13 03:21 出处:网络
G开发者_开发问答reetings I want to slugify/normalize utf8 string however I get # -*- coding: utf-8 -*-

G开发者_开发问答reetings

I want to slugify/normalize utf8 string however I get

# -*- coding: utf-8 -*-   
from django.template.defaultfilters import slugify
print slugify( unicode("şşşşüüüüççç") )

and get result as "ssssuuuccc", however I get UnicodeDecodeError 'ascii' codec cant decode ... error.


unicode() without an encoding argument tries to use ASCII to decode the given byte string, as a fail-safe default. unicode("şşşşüüüüççç") can't work as the string is not ASCII.

Use a unicode string literal:

print slugify(u"şşşşüüüüççç")

(and of course ensure that your text editor saves the script file using the UTF-8 encoding.)

0

精彩评论

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