from django.shortcuts import HttpResponse import simplejson as json class ResObject(object): def __init__(self, lang='cn'): self.lang = lang def json(self, code, res={}, extra={'msg': ''}): msg_data = { 0: 'Success', 10: extra['msg'] } result = {'code': code, 'msg': msg_data[code], 'res': res} if extra: for k in extra: result[k] = extra[k] return HttpResponse(json.dumps(result, ensure_ascii=False))