I'm trying to write an APIView using the Django REST framework. In the POST method I want to check if the request data contains anything, because I often get KeyError.
I can achieve it using the following code:
if request.data is not None and request.data != {}:
username = request.data["username"]
Is there a better way to write the above code? Especially request.data != {}