profile change photo
This commit is contained in:
SDE
2023-10-22 14:21:18 +03:00
parent 0ab9631e0f
commit adee3383ce

View File

@@ -75,13 +75,20 @@ def change_avatar_confirm_ajax(request):
if request.method != 'POST':
raise Http404
data = json.loads(request.body)
file_data = json.loads(data[0])
head, content = file_data['file'].split(',')
content = base64.b64decode(content)
file = ContentFile(content)
request.user.user_profile.avatar.save(file_data['file_name'], file)
request.user.user_profile.save(update_fields=['avatar'])
try:
data = json.loads(request.body)
file_data = json.loads(data[0])
head, content = file_data['file'].split(',')
content = base64.b64decode(content)
file = ContentFile(content)
request.user.user_profile.avatar.save(file_data['file_name'], file)
request.user.user_profile.save(update_fields=['avatar'])
except Exception as e:
msg = f'change_avatar_confirm_ajax Error = {str(e)}'
print(msg)
JsonResponse({'error': msg})
return JsonResponse({'url': request.user.user_profile.avatar.url})