0
@csrf_exempt
def registerSeller(request):
    print(request.body)
    data = json.loads(request.body.decode('utf-8'))

i am new for django and trying to build api with out django restframework and this is the output for request.body but it gives me error

AttributeError: 'bytes' object has no attribute 'read'

request.body 

b'-----------------------------344288735834045826241553250616\r\nContent-Disposition: form-data; name="username"\r\n\r\nabe7\r\n-----------------------------344288735834045826241553250616\r\nContent-Disposition: form-data; name="password"\r\n\r\n123\r\n-----------------------------344288735834045826241553250616\r\nContent-Disposition: form-data; name="phonenumber"\r\n\r\n091010101\r\n-----------------------------344288735834045826241553250616\r\nContent-Disposition: form-data; name="email"\r\n\r\nemail@gmial.com\r\n-----------------------------344288735834045826241553250616\r\nContent-Disposition: form-data; name="shop_description"\r\n\r\ndescription new\r\n-----------------------------344288735834045826241553250616\r\nContent-Disposition: form-data; name="shop_name"\r\n\r\nname new\r\n-----------------------------344288735834045826241553250616\r\nContent-Disposition: form-data; name="images"\r\n\r\n[object File],[object File],[object File]\r\n-----------------------------344288735834045826241553250616--\r\n'
leburik89
  • 5
  • 4

1 Answers1

1

You're getting multipart form data, not JSON data. You could access that with request.POST and request.FILES.

If you want something that can accept both that and JSON data, you would need to look at the Content-type request header and parse the data as JSON only if the content type is something like application/json.

AKX
  • 152,115
  • 15
  • 115
  • 172