• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python serializers.SnippetSerializer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中snippets.serializers.SnippetSerializer的典型用法代码示例。如果您正苦于以下问题:Python SnippetSerializer类的具体用法?Python SnippetSerializer怎么用?Python SnippetSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SnippetSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: snippet_detail

def snippet_detail(request, pk):
    """
    Retrieve, update or delete a code snippet.
    """
    try:
        snippet = Snippet.objects.get(pk=pk)
    except Snippet.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = SnippetSerializer(snippet)
        return JSONResponse(serializer.data)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = SnippetSerializer(snippet, data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data)
        return JSONResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        snippet.delete()
        return HttpResponse(status=204)
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,
                      IsOwnerOrReadOnly,)
开发者ID:Sasikumar-P,项目名称:WebApp_version2,代码行数:27,代码来源:views.py


示例2: post

	def post(self, request, format=None):
		data = JSONParser().parse(request)
		serializer = SnippetSerializer(data=data)
		if serializer.is_valid():
			serializer.save()
			return Response(serializer.data, status=status.HTTP_201_CREATED)
		return Response(serializer.data, status = status.HTTP_400_BAD_REQUEST)
开发者ID:ppeiris,项目名称:django-rest-tutorials,代码行数:7,代码来源:views_with_APIView_Class.py


示例3: post

 def post(self, request, format=None):
   serializer = SnippetSerializer(data=request.data)
   if serializer.is_valid():
     # The create() method of our serializer will now be passed an additional 'owner' field, along with the validated data from the request.
     serializer.save(owner=self.request.user)
     return Response(serializer.data, status=status.HTTP_201_CREATED)
   return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:Sticksword,项目名称:django_rest_framework_example,代码行数:7,代码来源:views.py


示例4: post

	def post(self, request, format = None):
		serializer = SnippetSerializer(request.data)
		if serializer.is_valid():
			serializer.save()
			return Response(serializer.data, status = status.Http_201_CREATE)
		return Response(serializer.errors, status = status.Http_400_BAD_REQUEST)
		pass
开发者ID:alfredyuanyi,项目名称:djangobook,代码行数:7,代码来源:views.py


示例5: put

 def put(self, request, pk, format=None):
     snippet = self.get_object(pk)
     serializer = SnippetSerializer(snippet, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:niyoufa,项目名称:djangorestserver,代码行数:7,代码来源:views.py


示例6: snippet_detail

def snippet_detail(request, pk):
    """
    Retrieve, update, or delete a code snippet.
    :param request:
    :param pk:
    :rtype: JSONResponse
    :return:
    """
    try:
        snippet = Snippet.objects.get(pk=pk)
    except Snippet.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = SnippetSerializer(snippet)
        return JSONResponse(serializer.data)
    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = SnippetSerializer(snippet, data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data)
        return JSONResponse(serializer.errors, status=400)
    elif request.method == 'DELETE':
        snippet.delete()
        return HttpResponse(status=204)
开发者ID:Fapiko,项目名称:django_tutorial,代码行数:26,代码来源:views.py


示例7: snippet_detail_api

def snippet_detail_api(request, id):
	"""
	Retrieve, update or delete a code snippet.
	"""
	try:
		snippet = Snippet.objects.raw_query({'rea' : int(id)})
		# print JSONResponse(snippet.data)
	except Snippet.DoesNotExist:
		return HttpResponse(status=404)

	if request.method == 'GET':

		if snippet:
			all_avisos = snippet.values('rea')[0]
			serializer = SnippetSerializer(all_avisos)
			return JSONResponse(serializer.data)
		else:
			all_avisos = [{"Message":"No duplicated ads found."}]
		
		return JSONResponse(all_avisos)
		

	elif request.method == 'PUT':
		data = JSONParser().parse(request)
		serializer = SnippetSerializer(snippet, data=data)
		if serializer.is_valid():
			serializer.save()
			return JSONResponse(serializer.data)
		return JSONResponse(serializer.errors, status=400)

	elif request.method == 'DELETE':
		snippet.delete()
		return HttpResponse(status=204)
开发者ID:marcosbeto,项目名称:deduplication,代码行数:33,代码来源:views.py


示例8: snippet_detail

def snippet_detail(request, pk):
    """
    코드 조각 조회, 업데이트, 삭제
    """
    try:
        snippet = Snippet.objects.get(pk=pk)
    except Snippet.DoesNotExist:
        return HttpResponse(status=404)


    if request.method == 'GET':
        serializer = SnippetSerializer(snippet)
        return JSONResponse(serializer.data)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = SnippetSerializer(snippet, data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data)
        return JSONResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        snippet.delete()
        return HttpResponse(status=204)
开发者ID:lanieerts,项目名称:restfw_2,代码行数:25,代码来源:views.py


示例9: snippet_detail

def snippet_detail(request, month, year):
    """
    Retrieve, update or delete a code snippet.
    """

    try:
        #snippet = Analysis.objects.filter(created__month=month,created__year=year,created__day=4,created__hour__gte=9)
        snippet = Analysis.objects.filter(user_id__contains = 1030)
    except Analysis.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = SnippetSerializer(snippet, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = SnippetSerializer(snippet, data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data)
        return JSONResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        snippet.delete()
        return HttpResponse(status=204)
开发者ID:bharatsush,项目名称:django_rest_framwork,代码行数:26,代码来源:views.py


示例10: post

	def post(self,request):
		data = JSONParser().parse(request)
		serializer = SnippetSerializer(data=data)
		if serializer.is_valid():
			serializer.save()
			return JSONResponse(serializer.data,status=201)
		return JSONResponse(serializer.errors,status=400)
开发者ID:enixdark,项目名称:django-rest-pratices,代码行数:7,代码来源:views.py


示例11: snippet_detail

def snippet_detail(request, pk):
    """
    Retrieve, update or delete a snippet instance.
    """
    try:
        snippet = Snippet.objects.get(pk=pk)
    except Snippet.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = SnippetSerializer(snippet)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = SnippetSerializer(snippet, data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        snippet.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
开发者ID:Bazzinga,项目名称:django-rest-framework-tutorial,代码行数:25,代码来源:views.py


示例12: snippet_detail

def snippet_detail(request, pk, format=None):
    """
    Retrieve, update or delete a code snippet.
    """
    try:
        snippet = Snippet.objects.get(pk=pk)
    except Snippet.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = SnippetSerializer(snippet)
        return Response(serializer.data)

    elif request.method == 'PUT':
	#use resquest.data repalce data
        #data = JSONParser().parse(request)
        serializer = SnippetSerializer(snippet, data=resquest.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=400)

    elif request.method == 'DELETE':
        snippet.delete()
        return HttpResponse(status=204)
开发者ID:shellyhh,项目名称:myblogsite,代码行数:25,代码来源:views.py


示例13: snippet_detail

def snippet_detail(request, pk, format=None):
    """
    Retrieve, update or delete a code snippet.
    """
    try:
        snippet = Snippet.objects.get(pk=pk)
    except Snippet.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = SnippetSerializer(snippet)
        return Response(serializer.data)

    elif request.method == 'PUT':
        # data = JSONParser().parse(request)
        # serializer = SnippetSerializer(snippet, data=data)
        serializer = SnippetSerializer(snippet, data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        snippet.delete()
        return Response(status=status.HTTP_200_OK)
开发者ID:AnthonyHonstain,项目名称:drf-tutorial-p3,代码行数:25,代码来源:views.py


示例14: post

 def post(self, request, format=None):
     serializer = SnippetSerializer(data=request.data)
     if serializer.is_valid():
         #serializer.save()
         self.perform_create(serializer)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:j-tamayo,项目名称:django_rest,代码行数:7,代码来源:views.py


示例15: snippet_detail

def snippet_detail(request, id):
	"""
	Retrieve, update or delete a code snippet.
	"""
	try:
		snippet = Snippet.objects.raw_query({'rea' : int(id)})
		
		if not snippet:
			return HttpResponse(status=404)

		all_avisos = snippet.values('rea')[0]
	except Snippet.DoesNotExist:
		return HttpResponse(status=404)

	if request.method == 'GET':
		serializer = SnippetSerializer(all_avisos)
		context = {'duplicateds_avisos': all_avisos['rea']}

		return render(request, 'duplicateds.html', context)

	elif request.method == 'PUT':
		data = JSONParser().parse(request)
		serializer = SnippetSerializer(snippet, data=data)
		if serializer.is_valid():
			serializer.save()
			return JSONResponse(serializer.data)
		return JSONResponse(serializer.errors, status=400)

	elif request.method == 'DELETE':
		snippet.delete()
		return HttpResponse(status=204)
开发者ID:marcosbeto,项目名称:deduplication,代码行数:31,代码来源:views.py


示例16: test_stream

    def test_stream(self):
        content = JSONRenderer().render(self.serializer.data)
        stream = StringIO.StringIO(content)
        data = JSONParser().parse(stream)

        serializer = SnippetSerializer(data=data)
        self.assertTrue(serializer.is_valid())
        for attribute in ("title", "code", "linenos", "language", "style"):
            self.assertEquals(getattr(serializer.object, attribute), getattr(self.snippet, attribute))
开发者ID:azkanurunala,项目名称:django-rest-framework-tutorial,代码行数:9,代码来源:tests.py


示例17: snippet_list

def snippet_list(request):
	if request.method == 'GET':
		snippets = Snippet.objects.all()
		serializer = SnippetSerializer(snippets,many=True)
		return Response(serializer.data)
	elif request.method == 'POST':
		serializer = SnippetSerializer(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_404_BAD_REQUEST)
开发者ID:zhijiasun,项目名称:tutorial,代码行数:11,代码来源:views.py


示例18: snippet_list

def snippet_list(request):
    if request.method == "GET":
        snippets = Snippet.objects.all()
        serializer = SnippetSerializer(snippets, many=True)
        return Response(serializer.data)
    elif request.method == "POSt":
        serializer = SnippetSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_100_CONTINUE)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:kumarsuresh521-netsol,项目名称:Python-tutorials,代码行数:11,代码来源:views.py


示例19: snippet_list

def snippet_list(request):
    if request.method == 'GET':
        snippets = Snippet.objects.all()
        serializer = SnippetSerializer(snippets, many=True)
        return JSONResponse(serializer.data)
    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = SnippetSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)
开发者ID:mzeeshanid,项目名称:pythonlearning-userauth,代码行数:12,代码来源:views.py


示例20: snippet_list

def snippet_list(request, format = None):

	if request.method == 'GET':
		snippets = Snippet.objects.all()
		serializer = SnippetSerializer(snippets, many=True)
		return Response(serializer.data)

	elif request.method == 'POST':
		data = JSONParser().parse(request)
		serializer = SnippetSerializer(data=data)
		if serializer.is_valid():
			serializer.save()
			return Response(serializer.data, status=status.HTTP_201_CREATED)
		return Response(serializer.data, status = status.HTTP_400_BAD_REQUEST)
开发者ID:ppeiris,项目名称:django-rest-tutorials,代码行数:14,代码来源:views_function_based_.py



注:本文中的snippets.serializers.SnippetSerializer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python Entities.Entity类代码示例发布时间:2022-05-27
下一篇:
Python tests.SnippetTemplateFactory类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap