开发者

Django queries: __iexact doesn't work with non-ASCII?

开发者 https://www.devze.com 2023-03-16 20:40 出处:网络
>>> p = Pet(kind=\"Кошка\") >>> p.kind \'\\xd0\\x9a\\xd0\\xbe\\xd1\\x88\\xd0\\xba\\xd0\\xb0\'
>>> p = Pet(kind="Кошка")
>>> p.kind
'\xd0\x9a\xd0\xbe\xd1\x88\xd0\xba\xd0\xb0'
>>> p.save()
>>> Pet.objects.get(kind__iexact="кошка")
Traceback... # some traces
DoesNotExist: Pet matching query does not exist.
>&开发者_运维问答gt;> p = Pet(kind="Cat")
>>> p.save()
>>> Pet.objects.get(kind__iexact="cat")
<Pet: Pet object>

Or there are db-level reasons (i'm using sqlite3)?


That's not Unicode.

p = Pet(kind=u"Кошка")
p.save()
print Pet.objects.get(kind__iexact=u"кошка")


The point is in the sqlite3 database itself, it does not support case-insensitive search for non-ASCII characters

0

精彩评论

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