We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
master
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.
snippet_list
result of both pprint : {u'code': u'print 12dgdf3'} <QueryDict: {}>
{u'code': u'print 12dgdf3'}
<QueryDict: {}>
result of both pprint : {u'code': u'print 12dgdf3'} {u'code': u'print 12dgdf3'}
The text was updated successfully, but these errors were encountered:
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
Sorry, something went wrong.
mybad .. only form-data is is available in in request.POST
Correct, yup. Use request.data.
request.data
if someone is interested where to find the official answer:
https://www.django-rest-framework.org/tutorial/2-requests-and-responses/#request-objects
I still don't understand why POST is empty. :( Any tutorial or link?
POST
No branches or pull requests
Checklist
master
branch of Django REST framework.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'}
The text was updated successfully, but these errors were encountered: