ResponseObject.py 977 B

12345678910111213141516171819202122232425262728293031
  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. 10: res,
  10. 233: '您已抽过奖',
  11. 300: '请输入正确的手机号码',
  12. 301: '验证码已发过,请等待',
  13. 309: 'Please ReLogin! errmsg token',
  14. 401: 'Invalid credentials !',
  15. 403: 'permission denied',
  16. 404: 'Server error',
  17. 407: '验证码过期',
  18. 409: '验证码错误',
  19. 414: 'Invalid request path !',
  20. 444: 'Wrong Parameter!',
  21. 473: 'The same value exists !'
  22. }
  23. result = {'code': code, 'msg': msg_data[code], 'res': res}
  24. if extra:
  25. for k in extra:
  26. result[k] = extra[k]
  27. return HttpResponse(json.dumps(result))