ResponseObject.py 702 B

123456789101112131415161718192021222324
  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. 403: 'permission denied',
  12. 404: 'Server error',
  13. 414: 'Invalid request path !',
  14. 444: 'Wrong Parameter!'
  15. }
  16. result = {'code': code, 'msg': msg_data[code], 'res': res}
  17. if extra:
  18. for k in extra:
  19. result[k] = extra[k]
  20. return HttpResponse(json.dumps(result))