[Fixed]-Django REST Framework – Set request in serializer test?

20👍

You need to pass context argument to add request1 to serializer’s context while instantiating the serializer in your test.

From DRF docs on including extra context:

You can provide arbitrary additional context by passing a context
argument when instantiating the serializer.

You need to do something like:

# pass context argument
self.serializer = ConferenceSerializer(context={'request': request1})

This will provide the desired request1 object to your serializer in its context.

Leave a comment