How to use the djangorestframework.response.Response function in djangorestframework

To help you get started, we’ve selected a few djangorestframework examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tranvictor / truongnha / api / views.py View on Github external
    @need_login
    def get(self, request, ids):
        user = request.user
        ids = ids.split('-')
        _smses = sms.objects.filter(id__in=ids, sender=user)
        result = {}
        for s in _smses:
            result[s.id] = '%s-%s' % (s.recent, s.success)
        return Response(status.HTTP_200_OK, content=result)
github encode / django-rest-framework / djangorestframework / response.py View on Github external
def _get_406_response(self):
        renderer = self.renderer_classes[0]
        return Response(
            {
                'detail': 'Could not satisfy the client\'s Accept header',
                'available_types': [renderer.media_type
                                    for renderer in self.renderer_classes]
            },
            status=status.HTTP_406_NOT_ACCEPTABLE,
            view=self.view, request=self.request, renderer_classes=[renderer])
github devilry / devilry-django / src / devilry_subjectadmin / devilry_subjectadmin / rest / group.py View on Github external
group_id = data['id']
            groupids.append(group_id)

        groups = self._query_groups_by_id(groupids)
        if len(groups) != len(datalist):
            raise NotFoundError('One or more of the requested groups does not exist.'.format(**vars()))
        with transaction.commit_on_success():
            for group in groups:
                manager = GroupManager(request.user, assignment_id, group)
                try:
                    manager.delete()
                except ValidationError, e:
                    raise ValidationErrorResponse(e)
                else:
                    logger.warning('User=%s deleted AssignmentGroup id=%s', self.user, group.id)
            return Response(204, '')
github devilry / devilry-django / src / devilry_subjectadmin / devilry_subjectadmin / rest / deadlinesbulk.py View on Github external
def post(self, request, id):
        deadlines = self._add_deadlines()
        groups = deadlines_as_groupobjects(deadlines)
        assignment_id = self.kwargs['id']
        content = create_deadlinedict(assignment_id=assignment_id,
                                      deadlines=deadlines)
        return Response(status=201, content=content)
github paulmillr / chieftain / api1 / views.py View on Github external
raise ErrorResponse(status.NOT_FOUND)

        key = get_key(request.GET["password"])
        if file.post.password == key:
            file.remove()
        elif is_mod(request, file.post.section_slug()):
            mod_delete_post(request, file.post)
            file.remove()
        else:
            raise ErrorResponse(status.FORBIDDEN, content={
                "detail": u"{}{}. {}".format(
                    _("Error on deleting file #"), file.post.pid,
                    _("Password mismatch")
                )
            })
        return Response(status.NO_CONTENT)
github encode / django-rest-framework / djangorestframework / views.py View on Github external
def handle_exception(self, exc):
        """
        Handle any exception that occurs, by returning an appropriate response,
        or re-raising the error.
        """
        if isinstance(exc, exceptions.Throttled):
            self.headers['X-Throttle-Wait-Seconds'] = '%d' % exc.wait

        if isinstance(exc, exceptions.APIException):
            return Response({'detail': exc.detail}, status=exc.status_code)
        elif isinstance(exc, Http404):
            return Response({'detail': 'Not found'},
                            status=status.HTTP_404_NOT_FOUND)
        elif isinstance(exc, PermissionDenied):
            return Response({'detail': 'Permission denied'},
                            status=status.HTTP_403_FORBIDDEN)
        raise
github encode / django-rest-framework / examples / resourceexample / views.py View on Github external
def post(self, request, num):
        """
        Handle POST requests, with form validation.
        Returns a simple string indicating what content was supplied.
        """
        if int(num) > 2:
            return Response(status.HTTP_404_NOT_FOUND)
        return "POST request to AnotherExampleResource %s, with content: %s" % (num, repr(self.CONTENT))
github encode / django-rest-framework / examples / views.py View on Github external
def get(self, request, *args, **kwargs):
        return Response()