I'm trying to use the django messages framework to show 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 can use the Django HttpRequest
from django rest framework Request
?
I went thru the source code and found my answer while typing out the question.
Django REST framework has a
Request
keep theHttpRequest
(or at least one compatible with django messages) in a_request
property. So, this works: