I'm Using Rest framework <http://www.django-rest-framework.org/> to get JSON
data and parse them. now I don't know how to access the second argument of
json data, for parse the json I've seen this link.
<http://www.django-rest-framework.org/api-guide/parsers/>
code in views:
@api_view(['POST'])@parser_classes((JSONParser,))def product_list(request):
"""
List all products which name of them is in the json data
"""
if request.method == 'POST':
print(request.data)
MarketProduct=[]
for item in request.data:
print(item)
try:
product=Market.objects.get(name=item)
MarketProduct.append(product)
except Market.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
serializer = MarketSerializer(MarketProduct, many=True)
return Response(serializer.data)
code in urls:
urlpatterns = [
url(r'^listproducts/$', views.product_list),
]
here in this line: for item in request.data: the item only has the first
argument of each json.
the json which I've sent is :
{'hello': '1', 'bye': '2'}
in printing items , only "hello" and "bye" prints.but i want to access "1"
and "2" too.
It's important for me to use Django framework. and I can't get the
appropriate way to use json.load(raw)
<http://stackoverflow.com/questions/14547916/how-can-i-loop-over-entries-in-json>
in this situation
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.