django rest framework send email

Solutions on MaxInterview for django rest framework send email by the best coders in the world

showing results for - "django rest framework send email"
Dashawn
15 Jul 2017
1Method-1 : override the create() method of ConsultViewSet
2
3def send_email():
4    email = EmailMessage(
5        'Title',
6        (ConsultSerializer.name, ConsultSerializer.email, ConsultSerializer.phone),
7        'my-email',
8        ['my-receive-email']
9    )
10    email.attach_file(ConsultSerializer.file)
11    email.send()
12
13
14class ConsultViewSet(viewsets.ModelViewSet):
15    queryset = Consult.objects.all()
16    serializer_class = ConsultSerializer
17
18    def create(self, request, *args, **kwargs):
19        response = super(ConsultViewSet, self).create(request, *args, **kwargs)
20        send_email()  # sending mail
21        return response