Django查询:__ iexact不能与非ASCII一起使用?

时间:2011-07-03 17:25:19

标签: django django-queryset

>>> 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.
>>> p = Pet(kind="Cat")
>>> p.save()
>>> Pet.objects.get(kind__iexact="cat")
<Pet: Pet object>

或者有db级别的原因(我正在使用sqlite3)?

1 个答案:

答案 0 :(得分:2)

那不是Unicode

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