Created
April 19, 2013 23:39
-
-
Save georgefs/5423989 to your computer and use it in GitHub Desktop.
django view json decoder
auto warp status & errormsg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def json_api(func): | |
def deco(*args, **kwargs): | |
result = {} | |
try: | |
result['status'] = 0 | |
result['msg'] = "success" | |
result['data'] = func(*args, **kwargs) | |
except Exception,e: | |
result['status'] = e.errorno if hasattr(e, 'errorno') else 1 | |
result['msg'] = e.message | |
finally: | |
result = json.dumps(result) | |
return HttpResponse(result, content_type="application/json") | |
return deco |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment