序列化后将<unicode>转换为str并在django中使用smart_text()

时间:2016-01-13 19:40:58

标签: python django unicode

由于某种原因,smart_text()实用程序未将unicode转换为字符串。

我有序列化的数据,如下所示:

{u'text': u'alskdfkld', u'chatroom': OrderedDict([(u'id', 18), ('created_at', u'2016-01-13T18:41:26.517572Z'), ('creator', 29), ('participant', 33)]), u'written_at': u'2016-01-13T19:27:49.118914Z', u'author': OrderedDict([(u'id', 29), ('password', u'pbkdf2_sha256$24000$h0whlzx0BleT$4cUWdRkUsPYB7Ia6F+pYxX+31BMhJJfpWiLHfoL9NOY='), ('last_login', u'2016-01-12T21:06:40.574122Z'), ('email', u'superman@gmail.com'), ('username', u'superman'), ('first_name', u'clark'), ('last_name', u'kent'), ('is_active', True), ('is_admin', False), ('joined_on', u'2016-01-06T23:57:43.191484Z'), ('is_online', True), ('is_contractor', False), ('profile_pic', '/media/bicycle_z3NDBPI.jpeg'), ('rating', None), ('address', u''), ('braintree_id', u'20401140'), ('socket_id', u'awnxF65jy2suqNRHAAAE'), ('subcategory', None)])}

然后我通过smart_text()传递它:

context = smart_text(context, encoding='utf-8', strings_only=False, errors='strict')

输出看起来完全一样。

我是否应该使用其他实用程序进行此转换?

0 个答案:

没有答案