[Answer]-How to pass a context through django's rest_framework

1👍

The problem with rendering multiple context items is that you don’t have access to their keys inside of a template. You need to hack on it a lil’ bit.

There’s a relevant SO question I have answered, which solves this issue. So basicaly you do:

serializer_context = {'request': request, 'pictures': pictures, 'filter': FilterForm()}

if request.accepted_renderer.format == 'html':
    return Response(serializer_context, template_name='index.html')

serializer = PaginatedPictureSerializer(pictures, context=serializer_context)
return Response(serializer.data, template_name='index.html')

Leave a comment