Answer the question
In order to leave comments, you need to log in
Can you please explain what this function does?
Greetings. Can you please explain what this piece of code does?
Interested in the moment with with open .... and the cycle itself
def upload_picture(request):
try:
f = request.FILES['picture']
filename = django_settings.MEDIA_ROOT + '/profile_pictures/' + request.user.username + '_tmp.jpg'
with open(filename, 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
pass
.....
Answer the question
In order to leave comments, you need to log in
when uploading, the file usually comes not in its entirety, but in pieces,
so the file is collected,
this code collects the file from pieces ,
but it is better to use it through the form for the model
form = ImageForm(request.POST, request.FILES)
if form.is_valid():
form.save()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question