Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request.POST is empty querydict when data posted using browsable api, when posted with hhtpie .. its fine #4046

Closed
4 tasks done
rjdp opened this issue Apr 11, 2016 · 4 comments

Comments

@rjdp
Copy link

rjdp commented Apr 11, 2016

Checklist

  • [x ] I have verified that that issue exists against the master branch of Django REST framework.
  • [x ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

step 1 . When data posted to apiview , pprint the POST querydict.

@api_view(['GET', 'POST'])
def snippet_list(request):
if request.method == 'POST':
from pprint import pprint as pp
pp(request.data)
pp(request.POST)
serializer = SnippetSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

step 2 . Post '{"code": "print 123"}' from browsable api to snippet_list apiview.

Expected behavior

result of both pprint : {u'code': u'print 12dgdf3'}
<QueryDict: {}>

Actual behavior

result of both pprint : {u'code': u'print 12dgdf3'}
{u'code': u'print 12dgdf3'}

@rjdp
Copy link
Author

rjdp commented Apr 11, 2016

mybad .. only form-data is is available in in request.POST , I assumed any data sent using Http POST will be in request.POST . closing this issue, tnx

@rjdp rjdp closed this as completed Apr 11, 2016
@tomchristie
Copy link
Member

mybad .. only form-data is is available in in request.POST

Correct, yup. Use request.data.

@danilo73r
Copy link

if someone is interested where to find the official answer:

https://www.django-rest-framework.org/tutorial/2-requests-and-responses/#request-objects

@RahulKushwaha
Copy link

RahulKushwaha commented Sep 17, 2019

I still don't understand why POST is empty. :(
Any tutorial or link?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants