如何使用rest-frameWork将POST数据插入Django模型

时间:2013-04-18 14:14:12

标签: python django django-models django-views django-rest-framework

我正在尝试使用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来发布数据...

0 个答案:

没有答案