Skip to main content

Django app for customizing response

Project description

Django rest framework app for customizing response data

Installation

pip install django-saccess-response

Usage

from saccess_response.response import SaccessResponse
from rest_framework.views import APIView


class MyView(APIView):
    @staticmethod
    def get(request):
        data = {'key': 'value'}
        return SaccessResponse(data)

result:

{
    "status": true,
    "result": {
        "key": "value"
    }
}

Error Handling

from saccess_response.response import SaccessResponse
from rest_framework.views import APIView

class MyView(APIView):
    @staticmethod
    def get(request):
        data = {'key': 'value'}
        return SaccessResponse(data, saccess=False)

result:

{
    "status": false,
    "result": {
        "detail": "error"
    }
}

Custom Django Rest Framework error handling

REST_FRAMEWORK = {
    'EXCEPTION_HANDLER': 'saccess_response.views.saccess_exception_handler'
}

Ganeric View and ViewSet class name

  • CreateAPIView: SaccessCreateAPIView
  • RetrieveAPIView: SaccessRetrieveAPIView
  • UpdateAPIView: SaccessUpdateAPIView
  • DestroyAPIView: SaccessDestroyAPIView
  • ListAPIView: SaccessListAPIView
  • RetrieveUpdateAPIView: SaccessRetrieveUpdateAPIView
  • RetrieveDestroyAPIView: SaccessRetrieveDestroyAPIView
  • RetrieveUpdateDestroyAPIView: SaccessRetrieveUpdateDestroyAPIView
  • ModelViewSet: SaccessModelViewSet
  • ReadOnlyModelViewSet: SaccessReadOnlyModelViewSet

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_saccess_response-1.0.1.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

django_saccess_response-1.0.1-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page