how to fetch user details and send it to his email address using django rest framework

0 votes
i need to fetch the user details and need to send his email address to his crediantials..
Aug 18, 2020 in Python by mahesh
• 120 points
4,332 views

1 answer to this question.

0 votes

Hello @mahesh,

First you have to fetch user details. I have created Models UserProfile, serilzers and ModelViewSet like below. From below models I  fetch loged in User profile details like state, city and adress etc.

class UserProfile(models.Model):
    user= models.OneToOneField(User,on_delete=models.CASCADE,related_name='userprofile');
    state= models.CharField(max_length=200)
    city= models.CharField(max_length=200)
    add1= models.CharField(max_length=200)
    add2= models.CharField(max_length=200)
    postalcode= models.IntegerField()
    country= models.CharField(max_length=200)

class UserProfileSerializer(serializers.ModelSerializer):

class Meta:
    model = UserProfile
    fields = ('state','city','country')

class UserProfileViewSet(viewsets.ModelViewSet):
    queryset=UserProfile.objects.all()
    serializer_class=UserProfileSerializer
    def get(self, request):
        userProfileObj = queryset.objects.filter(user_id=request.user.id)
        serializer = self.get_serializer(userProfileObj)
        return Response(serializer.data)

After this you can send email to users . To know how to send mail you can refer this:https://docs.djangoproject.com/en/3.1/topics/email/

Hope it helps!!

Thank You!!

answered Aug 18, 2020 by Niroj
• 82,840 points

Related Questions In Python

0 votes
1 answer

How to PATCH a single field using Django Rest Framework?

Hello @kartik, Serializers allow partial updates by specifying partial=True when initializing ...READ MORE

answered Jun 25, 2020 in Python by Niroj
• 82,840 points
15,393 views
0 votes
1 answer

How to secure APIs for Registration and Login in Django Rest Framework?

Hello @kartik, you cannot have an authentication system ...READ MORE

answered Jun 25, 2020 in Python by Niroj
• 82,840 points
2,879 views
0 votes
1 answer

How to update user password in Django Rest Framework?

Hello @kartik, Using a modelserializer might be an ...READ MORE

answered Jul 1, 2020 in Python by Niroj
• 82,840 points
9,240 views
0 votes
1 answer

How to test an API endpoint with Django-rest-framework using Django-oauth-toolkit for authentication?

Hello @kartik, You should avoid making unneeded API calls, ...READ MORE

answered Jul 2, 2020 in Python by Niroj
• 82,840 points
2,856 views
0 votes
0 answers

"Post Image data using POSTMAN"

I am trying to POST data to ...READ MORE

May 21, 2022 in Others by Kichu
• 19,040 points
1,094 views
0 votes
1 answer

how to download and install Django rest framework?

To install Django, you can simply open ...READ MORE

answered Apr 24, 2018 in Python by Christine
• 15,790 points
1,970 views
0 votes
1 answer

How to create login user using Django Rest Framework?

Hello @Reebika , For you query you can refer ...READ MORE

answered Oct 12, 2020 in Python by Niroj
• 82,840 points
821 views
0 votes
1 answer

How to return the current user with Django Rest Framework?

Hello @kartik, The best way is to use ...READ MORE

answered Jun 25, 2020 in Python by Niroj
• 82,840 points
12,036 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP