我正在尝试使用Django rest-frameWork将数据发布到我的Django应用程序......
我的观点是:
@csrf_view_exempt
class subscriptionsList(APIView):
def post(self, request, format=None):
key = self.request.QUERY_PARAMS.get('appKey', None)
keyData = app.objects.filter(appKey=key).exists()
if keyData == True:
serializer = PostSubscriptionDetailSerializer(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)
urls.py:
url(r'^subscribe/$',subscriptionsList,name='subscriptions-list'),
serializer.py
class PostSubscriptionDetailSerializer(serializers.ModelSerializer):
class Meta:
model = subscriptions
fields = ('subAppName','subStoreName','subTagName','emailID')
有人可以告诉我如何使用Django REST-frameWork来发布数据...