当前位置: 首页>>代码示例>>Python>>正文


Python SnippetSerializer.is_valid方法代码示例

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


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

示例1: snippet_detail

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
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,代码行数:27,代码来源:views.py

示例2: post

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
	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,代码行数:9,代码来源:views.py

示例3: snippet_detail

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
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,代码行数:27,代码来源:views.py

示例4: snippet_detail

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
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,代码行数:28,代码来源:views.py

示例5: snippet_detail

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
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,代码行数:33,代码来源:views.py

示例6: snippet_detail

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
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,代码行数:27,代码来源:views.py

示例7: put

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
 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,代码行数:9,代码来源:views.py

示例8: snippet_detail

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
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,代码行数:28,代码来源:views.py

示例9: post

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
	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,代码行数:9,代码来源:views_with_APIView_Class.py

示例10: snippet_detail

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
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,代码行数:29,代码来源:views.py

示例11: post

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
 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,代码行数:9,代码来源:views.py

示例12: post

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
	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,代码行数:9,代码来源:views.py

示例13: post

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
 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,代码行数:9,代码来源:views.py

示例14: snippet_detail

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
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,代码行数:27,代码来源:views.py

示例15: snippet_detail_api

# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import is_valid [as 别名]
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,代码行数:35,代码来源:views.py


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