How to get django HttpRequest from django rest Framework Request?

I am trying to use django's message structure to display messages after ModelViewSet.create() :

 class DomainModelViewSet(ModelViewSet): def create(self, request): super(DomainModelViewSet, self).create(request) messages.success(self.request, "Domain Added.") return HttpResponseRedirect(reverse('home')) 

But I get:

 TypeError: add_message() argument must be an HttpRequest object, not 'Request'. 

So how to use Django HttpRequest from the django rest Request framework?

+6
source share
1 answer

I went through the source code and found my answer by typing a question.

The Django REST structure has a Request to store an HttpRequest (or at least one compatible with django messages) in the _request property. So this works:

 messages.success(self.request._request, "Domain Added.") 
+9
source

All Articles