0👍
✅
HTML-page had a link to page, where is only the JSON-code. So, I made query to that page, and it works. Though, I have made the same query with Javascript and it worked with correct Content-Type header.
1👍
you can write a utility method and pass the arguments in that, for example
class JsonResponse(HttpResponse):
'''
Handling content type for json no more to add content-type.
'''
def __init__(self, content={}, status=None,content_type='application/json'):
super(JsonResponse, self).__init__(
json.dumps(content),
status=status, content_type=content_type)
after this you just need to pass the data to the above method like
response_json.update({"message": "success"})
return JsonResponse(response_json)
This might solve your issue.
0👍
Try using,
json.loads(request.body)
Json responses can be handled using this way.
- Trouble with Django urls
- How to perfom_create when the objet is created in the admin site. Django RestFramework
- Fetching model instance from a multiple direct relationship
- Django : Authenticated different user models
Source:stackexchange.com