Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created August 25, 2020 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/50e1dc9713879a73cb3765870347b2b0 to your computer and use it in GitHub Desktop.
Save velotiotech/50e1dc9713879a73cb3765870347b2b0 to your computer and use it in GitHub Desktop.
from rest_framework.renderers import JSONRenderer
from rest_framework.views import exception_handler
class CustomJSONRenderer(JSONRenderer):
def render(self, data, accepted_media_type=None, renderer_context=None):
# reformat the response
response_data = {"message": "", "errors": [], "data": data, "status": "success"}
# call super to render the response
response = super(CustomJSONRenderer, self).render(
response_data, accepted_media_type, renderer_context
)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment