23๐
โ
I think you have your answer there in the post youโve given.
You need to define custom JSON renderer
from rest_framework.renderers import JSONRenderer
class EmberJSONRenderer(JSONRenderer):
def render(self, data, accepted_media_type=None, renderer_context=None):
data = {'element': data}
return super(EmberJSONRenderer, self).render(data, accepted_media_type, renderer_context)
and use it as default renderer either in settings or as an explicitly defined render for you view, like:
class MyView(APIView):
renderer_classes = (EmberJSONRenderer, )
# ...
๐คmariodev
0๐
def finalize_response(self, request, response, *args, **kwargs):
response_code = response.status_code
resp = Response(data=response.data, status=response_code)
resp.accepted_renderer=request.accepted_renderer
resp.accepted_media_type = request.accepted_media_type
resp.renderer_context = self.get_renderer_context()
return resp
def get_renderer_context(self):
"""
Returns a dict that is passed through to Renderer.render(),
as the `renderer_context` keyword argument.
"""
# Note: Additionally 'response' will also be added to the context,
# by the Response object.
return {
'view': self,
'args': getattr(self, 'args', ()),
'kwargs': getattr(self, 'kwargs', {}),
'request': getattr(self, 'request', None)
}
๐คsaif alikhan
- How to have Accent-insensitive filter in django with postgres?
- Celerybeat automatically disables periodic task
- Using Django auth User model as a Foreignkey and reverse relations
- Pytest and Django settings runtime changes
Source:stackexchange.com