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


Python status.HTTP_404_NOT_FOUND屬性代碼示例

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


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

示例1: get_delete_update_puppy

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [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: stockcode_detail

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [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

示例3: ZXG_detail

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [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

示例4: BK_detail

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [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

示例5: test_read_message

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [as 別名]
def test_read_message(self):
        self.login_user1()
        url = reverse('message-api-list')
        message = {'recipient': 'u2', 'body': 'hello'}
        response = self.client.post(url, message, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.logout()
        # Change user
        self.login_user2()
        url = reverse('message-api-detail', kwargs={'pk': 1})
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['body'], 'hello')
        self.logout()
        # Change to another user (not in conversation)
        self.login_user3()
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.logout() 
開發者ID:narrowfail,項目名稱:django-channels-chat,代碼行數:21,代碼來源:test_api.py

示例6: test_get_refresth_token_detail

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [as 別名]
def test_get_refresth_token_detail(self):
        self.client.credentials(
            HTTP_AUTHORIZATION='JWT ' + utils.jwt_encode_handler(
                utils.jwt_payload_handler(self.user)))
        response = self.client.get(self.detail_url)
        self.assertEqual(
            response.status_code,
            status.HTTP_200_OK,
            (response.status_code, response.content)
        )
        response = self.client.get(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

示例7: test_delete_refresth_token

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [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

示例8: test_revoke_refresh_token

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [as 別名]
def test_revoke_refresh_token(self):
        self.client.credentials(
            HTTP_AUTHORIZATION='JWT ' + utils.jwt_encode_handler(
                utils.jwt_payload_handler(self.user)))
        response = self.client.post(self.revoke_url)
        self.assertEqual(
            response.status_code,
            status.HTTP_201_CREATED,
            (response.status_code, response.content)
        )
        new_rt = self.user.refresh_tokens.get()
        self.assertEqual(
            response.data,
            {'key': new_rt.key,
             'app': new_rt.app,
             'user': self.user.pk,
             'created': new_rt.created.isoformat()[:-6] + 'Z',
             })
        response = self.client.post(self.revoke_url)
        self.assertEqual(
            response.status_code,
            status.HTTP_404_NOT_FOUND,
            (response.status_code, response.content)
        ) 
開發者ID:lock8,項目名稱:django-rest-framework-jwt-refresh-token,代碼行數:26,代碼來源:test_long_refresh_token_views.py

示例9: test_token_view

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [as 別名]
def test_token_view(self):
        random_address = Account.create().address
        response = self.client.get(reverse('v1:token', args=(random_address,)))
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(response.data, {'detail': ErrorDetail(string='Not found.', code='not_found')})

        token = TokenFactory(address=random_address)
        response = self.client.get(reverse('v1:token', args=(random_address,)))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'address': token.address,
                                         'logo_uri': token.get_full_logo_uri(),
                                         'default': token.gas,
                                         'name': token.name,
                                         'symbol': token.symbol,
                                         'description': token.description,
                                         'decimals': token.decimals,
                                         'website_uri': token.website_uri,
                                         'gas': token.gas}) 
開發者ID:gnosis,項目名稱:safe-relay-service,代碼行數:20,代碼來源:test_views.py

示例10: get

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [as 別名]
def get(self, request, address, format=None):
        """
        Get status of the safe
        """
        if not Web3.isChecksumAddress(address):
            return Response(status=status.HTTP_422_UNPROCESSABLE_ENTITY)
        else:
            try:
                SafeContract.objects.get(address=address)
            except SafeContract.DoesNotExist:
                return Response(status=status.HTTP_404_NOT_FOUND)

            safe_balances = StatsServiceProvider().get_balances(address)
            serializer = self.serializer_class(data=safe_balances, many=True)
            # assert serializer.is_valid(), 'Safe Balance result not valid'
            serializer.is_valid()
            return Response(status=status.HTTP_200_OK, data=serializer.data) 
開發者ID:gnosis,項目名稱:safe-relay-service,代碼行數:19,代碼來源:views.py

示例11: test_safe_balances

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [as 別名]
def test_safe_balances(self):
        safe_address = Account.create().address
        response = self.client.get(reverse('v1:safe-balances', args=(safe_address, )))
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        SafeContractFactory(address=safe_address)
        value = 7
        self.send_ether(safe_address, 7)
        response = self.client.get(reverse('v1:safe-balances', args=(safe_address, )))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.json()), 1)
        self.assertIsNone(response.json()[0]['tokenAddress'])
        self.assertEqual(response.json()[0]['balance'], str(value))

        tokens_value = 12
        erc20 = self.deploy_example_erc20(tokens_value, safe_address)
        response = self.client.get(reverse('v1:safe-balances', args=(safe_address,)))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.json()), 1)

        EthereumEventFactory(token_address=erc20.address, to=safe_address)
        response = self.client.get(reverse('v1:safe-balances', args=(safe_address,)))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertCountEqual(response.json(), [{'tokenAddress': None, 'balance': str(value)},
                                                {'tokenAddress': erc20.address, 'balance': str(tokens_value)}]) 
開發者ID:gnosis,項目名稱:safe-relay-service,代碼行數:27,代碼來源:test_views.py

示例12: test_erc20_view

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [as 別名]
def test_erc20_view(self):
        safe_address = Account().create().address
        SafeContractFactory(address=safe_address)

        response = self.client.get(reverse('v1:erc20-txs', args=(safe_address,)))
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        ethereum_erc20_event = EthereumEventFactory(to=safe_address)
        response = self.client.get(reverse('v1:erc20-txs', args=(safe_address,)))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response_ethereum_erc20_event = response.json()['results'][0]
        self.assertEqual(ethereum_erc20_event.token_address, response_ethereum_erc20_event['tokenAddress'])
        self.assertEqual(ethereum_erc20_event.arguments['to'], response_ethereum_erc20_event['to'])
        self.assertEqual(ethereum_erc20_event.arguments['from'], response_ethereum_erc20_event['from'])
        self.assertEqual(ethereum_erc20_event.arguments['value'], int(response_ethereum_erc20_event['value']))
        self.assertEqual(ethereum_erc20_event.ethereum_tx.to, response_ethereum_erc20_event['ethereumTx']['to'])

        EthereumEventFactory(from_=safe_address)
        EthereumEventFactory()
        response = self.client.get(reverse('v1:erc20-txs', args=(safe_address,)))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['count'], 2) 
開發者ID:gnosis,項目名稱:safe-relay-service,代碼行數:24,代碼來源:test_views.py

示例13: test_erc721_view

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [as 別名]
def test_erc721_view(self):
        safe_address = Account().create().address
        SafeContractFactory(address=safe_address)

        response = self.client.get(reverse('v1:erc721-txs', args=(safe_address,)))
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        ethereum_erc721_event = EthereumEventFactory(to=safe_address, erc721=True)
        response = self.client.get(reverse('v1:erc721-txs', args=(safe_address,)))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response_ethereum_erc721_event = response.json()['results'][0]
        self.assertEqual(ethereum_erc721_event.token_address, response_ethereum_erc721_event['tokenAddress'])
        self.assertEqual(ethereum_erc721_event.arguments['to'], response_ethereum_erc721_event['to'])
        self.assertEqual(ethereum_erc721_event.arguments['from'], response_ethereum_erc721_event['from'])
        self.assertEqual(ethereum_erc721_event.arguments['tokenId'], int(response_ethereum_erc721_event['tokenId']))
        self.assertEqual(ethereum_erc721_event.ethereum_tx.to, response_ethereum_erc721_event['ethereumTx']['to'])

        EthereumEventFactory(from_=safe_address, erc721=True)
        EthereumEventFactory(erc721=True)
        response = self.client.get(reverse('v1:erc721-txs', args=(safe_address,)))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['count'], 2) 
開發者ID:gnosis,項目名稱:safe-relay-service,代碼行數:24,代碼來源:test_views.py

示例14: perform_create

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [as 別名]
def perform_create(self, serializer):
        try:
            device = Device.objects.get(dev_id=serializer.data["dev_id"])
        except Device.DoesNotExist:
            device = Device(dev_id=serializer.data["dev_id"])
        device.is_active = True
        device.reg_id = serializer.data["reg_id"]
        user = User.objects.filter(email__iexact=serializer.data["name"])
        if user:
            device.name = user[0].email
        else:
            user = User.objects.filter(username__iexact=serializer.data["name"])
            if user:
                device.name = user[0].email
            else:
                return response.Response(status=status.HTTP_404_NOT_FOUND)    
        device.save() 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:19,代碼來源:FieldsightFcmViewset.py

示例15: active_status

# 需要導入模塊: from rest_framework import status [as 別名]
# 或者: from rest_framework.status import HTTP_404_NOT_FOUND [as 別名]
def active_status(self, request):
        """
        This will only work if you have django-celery installed (for now).
        In case you only need to work with status codes to find out if the
        workers are up or not.
        This will only work if we assume our db only contains "active workers".
        To use this feature, you must ensure you use only named workers,
        For example: "-n worker1@localhost:8000".
        http://docs.celeryproject.org/en/latest/userguide/workers.html#starting-the-worker
        """

        app_installed = "djcelery" in settings.INSTALLED_APPS
        if not app_installed:
            return Response(status=status.HTTP_501_NOT_IMPLEMENTED)

        from djcelery.models import WorkerState

        count_workers = WorkerState.objects.all().count()
        result = self.inspect.active()

        if result is not None and count_workers == len(result):
            return Response(status=status.HTTP_200_OK)

        return Response(status=status.HTTP_404_NOT_FOUND) 
開發者ID:psychok7,項目名稱:django-celery-inspect,代碼行數:26,代碼來源:viewsets.py


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