Reputation: 402
I am trying to read request body using django but, it throws an error:
You cannot access body after reading from request's data stream
Here is my code:
@csrf_exempt
def update_profile(request):
"""
"""
if request.method == 'POST':
try:
# Validate
payload = json.loads(request.body)
# get files
profile_pic = request.FILES.get('profile_pic')
user_data = util.update_profile(obj_common, user_id, payload,profile_pic)
return user_data
I have seen many answer on the stackoverflow, They advice me to replace request.body with request.data.
but when it tried i got another error
{AttributeError}'WSGIRequest' object has no attribute 'data'
Upvotes: 1
Views: 712
Reputation: 184
Looks like request.POST
is being processed somewhere before calling this function. Try searching for it
Upvotes: 0