Python Django objects.filter在处理unicode时不一致

Python Django objects.filter在处理unicode时不一致,python,django,unicode,Python,Django,Unicode,通常,这样的过滤器会返回正确的结果: Entry.objects.filter(blog__name__startswith='Beatle') 但有时情况并非如此!我必须让它工作: Entry.objects.filter(blog__name__startswith=u'Beatle') 这是否意味着我们必须始终将unicode字符串放在那里,或者这是一个bug?有什么想法吗? 谢谢 九月视情况而定。向我们展示一个数据示例和查询行为,以及数据库信息及其编码/排序规则设置。通常,如果字符串

通常,这样的过滤器会返回正确的结果:

Entry.objects.filter(blog__name__startswith='Beatle')
但有时情况并非如此!我必须让它工作:

Entry.objects.filter(blog__name__startswith=u'Beatle')
这是否意味着我们必须始终将unicode字符串放在那里,或者这是一个bug?有什么想法吗? 谢谢
九月

视情况而定。向我们展示一个数据示例和查询行为,以及数据库信息及其编码/排序规则设置。通常,如果字符串具有unicode字符,那么您当然需要使用unicode?通常情况下,这不应该发生,但可能是编码问题。我正在尝试重新创建这种情况,但到目前为止一切正常。感谢Dmitry和Miki,我正在尝试重新创建这种情况,但到目前为止一切正常,无需将u。我在windows上使用MySQL 5.5。Python 2.7。Django 1.4.1通过Python shell输入到Django的原始数据是Ascii。我的编码是Windows上的默认区域设置,可能是以前发生的拉丁语1:M Blog到条目的关系>>>bbb=Blog.objects.getid=3>>>bbb.name u'Beatles Blog'>>>>Entry.objects.filterblog_uname_u_u_uendswith='Blog'[]>>Entry.objects.filterblog_uname_u开始使用='Beatles'[]>>>Entry.objects.filterblog\u_name\u_startswith=u'Beatles'[]视情况而定。向我们展示一个数据示例和查询行为,以及数据库信息及其编码/排序规则设置。通常,如果字符串具有unicode字符,那么您当然需要使用unicode?通常情况下,这不应该发生,但可能是编码问题。我正在尝试重新创建这种情况,但到目前为止一切正常。感谢Dmitry和Miki,我正在尝试重新创建这种情况,但到目前为止一切正常,无需将u。我在windows上使用MySQL 5.5。Python 2.7。Django 1.4.1通过Python shell输入到Django的原始数据是Ascii。我的编码是Windows上的默认区域设置,可能是以前发生的拉丁语1:M Blog到条目的关系>>>bbb=Blog.objects.getid=3>>>bbb.name u'Beatles Blog'>>>>Entry.objects.filterblog_uname_u_u_uendswith='Blog'[]>>Entry.objects.filterblog_uname_u开始使用='Beatles'[]>>>Entry.objects.filterblog\uuuuu name\uuuuu startswith=u'Beatles'[]