python - django-rest-framework JSON POST, request.data throws cannot access body after reading from request's data stream -
i'm tring build rest api using django-rest-framework , python 3.6, facing issue post requests
i can post json data using postman endpoint content-type set "application/json" , read dict doing request.data
. works if start server running
python manage.py runserver
however, when i'm debugging on visual studio code , django's standard httprequest object not overridden django-rest-framework's enhanced request object , raises rawpostdataexception("you cannot access body after reading request's data stream")
views.py
@csrf_exempt @api_view(['get', 'post']) @parser_classes((jsonparser,)) def customers(request): received_data = request.data
middlewares defined in settings.py
middleware = [ 'corsheaders.middleware.corsmiddleware', 'django.middleware.security.securitymiddleware', 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware', ]
installed apps in settings.py
installed_apps = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_mysql', 'api', 'installer', 'rest_framework', 'rest_framework.authtoken', 'corsheaders', 'django_celery_beat', ]
vs code's launch.json
{ "name": "django", "type": "python", "request": "launch", "stoponentry": false, "pythonpath": "/users/bharath/miniconda3/envs/shopify/bin/python", "program": "${workspaceroot}/backend/manage.py", "cwd": "${workspaceroot}/backend", "args": [ "runserver", "--noreload", "--nothreading", "--no-color" ], "env": {}, "envfile": "${workspaceroot}/.env", "debugoptions": [ "waitonabnormalexit", "waitonnormalexit", "redirectoutput", "djangodebugging" ] },
Comments
Post a Comment