I have a simple rest api which I want to send a post request to using requests.
My url pattern is this:
url(r'^$', views.ProductList.as_view()) Inside my view I have:
class ProductList(generics.ListAPIView): serializer_class = ProductSerializer def post(self, request, format=None): print('THIS IS A POST REQUEST') queryset = [product.name for product in Product.objects.all()] return Response(queryset) And I am trying to send a post request using:
response = requests.post('http://127.0.0.1:8080/') However this returns a 403, and the print statement isn't printed. I have done some research and I think it may have something to do with the CSRF token not being there but i'm not to sure how to add that. Does anybody know how I can get the post request to work?
I'm using python 3.6.3 and Django 1.10