Django Component
1412 浏览 6 years, 1 month
1 数据处理
版权声明: 转载请注明出处 http://www.codingsoho.com/unicdoe
代碼示例:
import unicodedata
from unidecode import unidecode
value = unicode(unidecode(value))
範例:
u'unicode測試許功蓋,你看到了嗎?' 轉換成 'unicodece-shi-xu-gong-gai-ni-kan-dao-liao-ma'
django-uuslug
from uuslug import slugify
txt = '你好我是中国人'
r = slugify(txt)
self.assertEquals(r, "nin-hao-wo-shi-zhong-guo-ren")
json string和dict的转化
import json
data1 = {'b': 789, 'c': 456, 'a': 123}
encode_json = json.dumps(data1)
print type(encode_json), encode_json
decode_json = json.loads(encode_json)
print type(decode_json)
print decode_json['a']
print decode_json