ResponseObject.py 664 B

1234567891011121314151617181920212223
  1. from django.shortcuts import HttpResponse
  2. import simplejson as json
  3. class ResponseObject(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. 309: 'Please ReLogin! errmsg token',
  10. 401: 'Invalid credentials !',
  11. 404: 'Server error',
  12. 414: 'Invalid request path !',
  13. 444: 'Wrong Parameter!'
  14. }
  15. result = {'code': code, 'msg': msg_data[code], 'res': res}
  16. if extra:
  17. for k in extra:
  18. result[k] = extra[k]
  19. return HttpResponse(json.dumps(result))