U
U
user-agent2021-08-20 22:56:08
Django
user-agent, 2021-08-20 22:56:08

How to update profile photo without using form?

I'm getting an image from an input and I want to update my profile photo in my views. How can I do this without using form, working exactly on the Profile object?

def profile_form(request):
  if request.method == 'POST':
    profile = Profile.objects.get(user=request.user)
    ...
    profile.save()
  return HttpResponseRedirect("/")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-08-20
@user-agent

profile.photo = request.FILES['photo']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question