ResObject.py 514 B

12345678910111213141516171819
  1. from django.shortcuts import HttpResponse
  2. import simplejson as json
  3. class ResObject(object):
  4. def __init__(self, lang='cn'):
  5. self.lang = lang
  6. def json(self, code, res={}, extra={'msg': ''}):
  7. msg_data = {
  8. 0: 'Success',
  9. 10: extra['msg']
  10. }
  11. result = {'code': code, 'msg': msg_data[code], 'res': res}
  12. if extra:
  13. for k in extra:
  14. result[k] = extra[k]
  15. return HttpResponse(json.dumps(result, ensure_ascii=False))