当前位置: 首页>>代码示例>>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;未经允许,请勿转载。