Here my urls.py
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^product/$', productviews, productviews.ProductList.as_view()),
url(r'^product/(?P<pk>[0-9]+)$', productviews.ProductDetail.as_view()),
]
*productviews.py*
from product.models import Product
from product.serializers import ProductSerializer
from rest_framework import generics
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
from django.http import HttpResponse
import json
class ProductList(generics.ListCreateAPIView):
queryset = Product
serializer_class = ProductSerializer
@method_decorator(csrf_exempt)
def post(self, request, *args, **kwargs):
received_json_data=json.loads(request.body.decode("utf8"))
serializer = ProductSerializer(data=received_json_data)
if serializer.is_valid():
serializer.save()
print (request.body)
return HttpResponse('SUCCESS')
else:
print (serializer.errors)
return HttpResponse('Error')
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/3bd15344-357e-4a6c-a7a1-0a7ad5a1131d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.