Updating profile image in django

512 views
Skip to first unread message

Nsikan Patrick

unread,
Dec 26, 2022, 12:53:04 PM12/26/22
to Django developers (Contributions to Django itself)
Hello everyone, so I have I have this issue when trying to update a profile photo in django.
The Profile photo actually updates if I upload an image. But there are cases where a user may want to update other details without updating the profile photo.
Trying to implement that gives me a multivalue error.
I've been on this for some time now, who knows how I can handle that.
Here's my code on views.py file

def profile_update(request, user_id):
    if request.method == 'POST':
        user_obj = User.objects.get(id=user_id)
        user_profile_obj = UserProfile.objects.get(user=user_id)

        user_img = request.FILES['user_img']
        username = request.POST["username"]
        email = request.POST["email"]
        phone = request.POST["phone"]
        address = request.POST["address"]

        fs_handle = FileSystemStorage()
        img_name = 'uploads/profile_pictures/user_{0}'.format(user_id)
        if fs_handle.exists(img_name):
            fs_handle.delete(img_name)
        fs_handle.save(img_name, user_img)

        user_profile_obj.profile_pic = img_name
       
        user_profile_obj.phone = phone
        user_profile_obj.address = address
        user_profile_obj.save()
        
        user_obj.username =  username
        user_obj.email = email
        user_obj.save()
        user_obj.refresh_from_db()

Adam Johnson

unread,
Dec 29, 2022, 7:16:52 AM12/29/22
to django-d...@googlegroups.com
Hi!

I think you've found the wrong mailing list for this post. This mailing list is for discussing the development of Django itself, not for support using Django. This means the discussions of bugs and features in Django itself, rather than in your code using it. People on this list are unlikely to answer your support query with their limited time and energy.

For support, please follow the "Getting Help" page: https://docs.djangoproject.com/en/stable/faq/help/ . This will help you find people who are willing to support you, and to ask your question in a way that makes it easy for them to answer.

Thanks for your understanding and all the best,

Adam

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ad3f98d1-c715-41e0-b05e-99e8be1f856cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages