當前位置: 首頁>>代碼示例>>Python>>正文


Python status.HTTP_204_NO_CONTENT屬性代碼示例

本文整理匯總了Python中rest_framework.status.HTTP_204_NO_CONTENT屬性的典型用法代碼示例。如果您正苦於以下問題:Python status.HTTP_204_NO_CONTENT屬性的具體用法?Python status.HTTP_204_NO_CONTENT怎麽用?Python status.HTTP_204_NO_CONTENT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在rest_framework.status的用法示例。


在下文中一共展示了status.HTTP_204_NO_CONTENT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_delete_update_puppy

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def get_delete_update_puppy(request, pk):
    try:
        puppy = Puppy.objects.get(pk=pk)
    except Puppy.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    # get details of a single puppy
    if request.method == 'GET':
        serializer = PuppySerializer(puppy)
        return Response(serializer.data)

    # update details of a single puppy
    if request.method == 'PUT':
        serializer = PuppySerializer(puppy, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_204_NO_CONTENT)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    # delete a single puppy
    if request.method == 'DELETE':
        puppy.delete()
        return Response(status=status.HTTP_204_NO_CONTENT) 
開發者ID:realpython,項目名稱:django-puppy-store,代碼行數:25,代碼來源:views.py

示例2: destroy

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def destroy(self, request, **kwargs):
        calling_obj = self.get_object()
        target_obj = calling_obj

        if request.data.get('username'):
            # if you "accidentally" target yourself, that should be fine
            if calling_obj.username == request.data['username'] or calling_obj.is_superuser:
                target_obj = get_object_or_404(User, username=request.data['username'])
            else:
                raise PermissionDenied()

        # A user can not be removed without apps changing ownership first
        if len(models.App.objects.filter(owner=target_obj)) > 0:
            msg = '{} still has applications assigned. Delete or transfer ownership'.format(str(target_obj))  # noqa
            raise AlreadyExists(msg)

        try:
            target_obj.delete()
            return Response(status=status.HTTP_204_NO_CONTENT)
        except ProtectedError as e:
            raise AlreadyExists(e) 
開發者ID:deis,項目名稱:controller,代碼行數:23,代碼來源:views.py

示例3: add_user

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def add_user(self, request, pk=None):
        group = self.get_object()

        if not request.data.get("user_id"):
            return Response(
                {"user_id": "This field is required."}, status=status.HTTP_400_BAD_REQUEST
            )

        try:
            user = User.objects.get(pk=request.data.get("user_id"))
        except User.DoesNotExist:
            return Response({"user_id": "Invalid user ID."}, status=status.HTTP_400_BAD_REQUEST)

        if request.user == user:
            return Response(status=status.HTTP_403_FORBIDDEN)

        user.groups.add(group)

        return Response(status=status.HTTP_204_NO_CONTENT) 
開發者ID:mozilla,項目名稱:normandy,代碼行數:21,代碼來源:views.py

示例4: remove_user

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def remove_user(self, request, pk=None):
        group = self.get_object()

        if not request.data.get("user_id"):
            return Response(
                {"user_id": "This field is required."}, status=status.HTTP_400_BAD_REQUEST
            )

        try:
            user = User.objects.get(pk=request.data.get("user_id"))
        except User.DoesNotExist:
            return Response({"user_id": "Invalid user ID."}, status=status.HTTP_400_BAD_REQUEST)

        if user.groups.filter(pk=group.pk).count() == 0:
            return Response(
                {"user_id": "User is not in group."}, status=status.HTTP_400_BAD_REQUEST
            )

        user.groups.remove(group)

        return Response(status=status.HTTP_204_NO_CONTENT) 
開發者ID:mozilla,項目名稱:normandy,代碼行數:23,代碼來源:views.py

示例5: destroy

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def destroy(self, request, *args, **kwargs):
        """
        Destroy an image instance.
        """
        image = self.get_object()

        logger.info("user %s deletes image: %s/%s:%s" % (
            request.user.username,
            image.user.username,
            image.name,
            image.version))

        destroyer = ImageDestroyer(image)
        destroyer.destroy_image_instance()

        return Response(status=status.HTTP_204_NO_CONTENT) 
開發者ID:wangtaoking1,項目名稱:hummer,代碼行數:18,代碼來源:views.py

示例6: stockcode_detail

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def stockcode_detail(request, pk, format=None):
    """
    Retrieve, update or delete a snippet instance.
    """
    try:
        values = SC.objects.get(pk=pk)
    except SC.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = ListingSerializer(values)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = ListingSerializer(values, 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':
        values.delete()
        return Response(status=status.HTTP_204_NO_CONTENT) 
開發者ID:pchaos,項目名稱:wanggeService,代碼行數:25,代碼來源:__init__.py

示例7: ZXG_detail

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def ZXG_detail(request, pk, format=None):
    """
    Retrieve, update or delete a snippet instance.
    """
    try:
        values = BlockDetail.objects.get(pk=pk)
    except BlockDetail.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = BKDetailSerializer(values)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = BKDetailSerializer(values, 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':
        values.delete()
        return Response(status=status.HTTP_204_NO_CONTENT) 
開發者ID:pchaos,項目名稱:wanggeService,代碼行數:25,代碼來源:__init__.py

示例8: BK_detail

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def BK_detail(request, pk, format=None):
    """
    Retrieve, update or delete a snippet instance.
    """
    try:
        values = BlockDetail.objects.get(pk=pk)
    except BlockDetail.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = BKDetailSerializer(values)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = BKDetailSerializer(values, 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':
        values.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)

# from .hsgtcgholdview import HSGTCG 
開發者ID:pchaos,項目名稱:wanggeService,代碼行數:27,代碼來源:__init__.py

示例9: test_delete_refresth_token

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def test_delete_refresth_token(self):
        self.client.credentials(
            HTTP_AUTHORIZATION='JWT ' + utils.jwt_encode_handler(
                utils.jwt_payload_handler(self.user)))
        response = self.client.delete(self.detail_url)
        self.assertEqual(
            response.status_code,
            status.HTTP_204_NO_CONTENT,
            (response.status_code, response.content)
        )
        response = self.client.delete(self.detail_url1)
        self.assertEqual(
            response.status_code,
            status.HTTP_404_NOT_FOUND,
            (response.status_code, response.content)
        ) 
開發者ID:lock8,項目名稱:django-rest-framework-jwt-refresh-token,代碼行數:18,代碼來源:test_long_refresh_token_views.py

示例10: share

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def share(self, request, *args, **kwargs):
        self.object = self.get_object()

        data = {}
        for key, val in request.data.iteritems():
            data[key] = val
        data.update({'xform': self.object.pk})

        serializer = ShareXFormSerializer(data=data)

        if serializer.is_valid():
            serializer.save()
        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(status=status.HTTP_204_NO_CONTENT) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:19,代碼來源:xform_viewset.py

示例11: star

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def star(self, request, *args, **kwargs):
        user = request.user
        project = get_object_or_404(Project, pk=kwargs.get('pk'))

        if request.method == 'DELETE':
            project.user_stars.remove(user)
        elif request.method == 'POST':
            project.user_stars.add(user)
        elif request.method == 'GET':
            users = project.user_stars.values('pk')
            user_profiles = UserProfile.objects.filter(user__in=users)
            serializer = UserProfileSerializer(user_profiles,
                                               context={'request': request},
                                               many=True)

            return Response(serializer.data)

        return Response(status=status.HTTP_204_NO_CONTENT) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:20,代碼來源:project_viewset.py

示例12: test_report_update_bulk

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def test_report_update_bulk(auth_client):
    task = TaskFactory.create()
    report = ReportFactory.create(user=auth_client.user)

    url = reverse("report-bulk")

    data = {
        "data": {
            "type": "report-bulks",
            "id": None,
            "relationships": {"task": {"data": {"type": "tasks", "id": task.id}}},
        }
    }

    response = auth_client.post(url + "?editable=1", data)
    assert response.status_code == status.HTTP_204_NO_CONTENT

    report.refresh_from_db()
    assert report.task == task 
開發者ID:adfinis-sygroup,項目名稱:timed-backend,代碼行數:21,代碼來源:test_report.py

示例13: test_report_update_bulk_verify_reviewer

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def test_report_update_bulk_verify_reviewer(auth_client):
    user = auth_client.user
    report = ReportFactory.create(user=user)
    report.task.project.reviewers.add(user)

    url = reverse("report-bulk")

    data = {
        "data": {
            "type": "report-bulks",
            "id": None,
            "attributes": {"verified": True, "comment": "some comment"},
        }
    }

    response = auth_client.post(url + "?editable=1&reviewer={0}".format(user.id), data)
    assert response.status_code == status.HTTP_204_NO_CONTENT

    report.refresh_from_db()
    assert report.verified_by == user
    assert report.comment == "some comment" 
開發者ID:adfinis-sygroup,項目名稱:timed-backend,代碼行數:23,代碼來源:test_report.py

示例14: test_status_delete

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def test_status_delete(self):
        data = self.create_item()
        data_id = data.get("id")
        rud_url = api_reverse('api-status:detail', kwargs={"id": data_id})
        rud_data = {
            'content': "another new content"
        }
        '''
        delete method / delete
        '''
        del_response = self.client.delete(rud_url, format='json')
        self.assertEqual(del_response.status_code, status.HTTP_204_NO_CONTENT)
        '''
        Not found
        '''
        get_response = self.client.get(rud_url, format='json')
        self.assertEqual(get_response.status_code, status.HTTP_404_NOT_FOUND) 
開發者ID:codingforentrepreneurs,項目名稱:REST-API,代碼行數:19,代碼來源:tests.py

示例15: test_valid_update_puppy

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_204_NO_CONTENT [as 別名]
def test_valid_update_puppy(self):
        response = client.put(
            reverse('get_delete_update_puppy', kwargs={'pk': self.muffin.pk}),
            data=json.dumps(self.valid_payload),
            content_type='application/json'
        )
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) 
開發者ID:realpython,項目名稱:django-puppy-store,代碼行數:9,代碼來源:test_views.py


注:本文中的rest_framework.status.HTTP_204_NO_CONTENT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。