Created
October 2, 2017 19:41
-
-
Save emmettna/b8846c425eb7f5feac23910d3ed68a63 to your computer and use it in GitHub Desktop.
Django Python3 UTF-8 Json decoder method
This file contains hidden or 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
from django.http import JsonResponse | |
import json | |
def get_json_data(data): | |
try: | |
return json.loads(data.body.decode('utf-8')) | |
except TypeError: | |
return JsonResponse({'response': 'Type Incorrect'}) | |
except Exception as e: | |
return JsonResponse({'response': 'Unexpected Error as follow : '+str(e)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment