ResponseObject.py 746 B

12345678910111213141516171819202122232425
  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. 473: 'The same value exists !'
  16. }
  17. result = {'code': code, 'msg': msg_data[code], 'res': res}
  18. if extra:
  19. for k in extra:
  20. result[k] = extra[k]
  21. return HttpResponse(json.dumps(result))