ResObject.py 476 B

123456789101112131415161718
  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={}):
  7. msg_data = {
  8. 0: 'Success',
  9. }
  10. result = {'code': code, 'msg': msg_data[code], 'res': res}
  11. if extra:
  12. for k in extra:
  13. result[k] = extra[k]
  14. return HttpResponse(json.dumps(result, ensure_ascii=False))