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

View File

@@ -75,6 +75,8 @@ def change_avatar_confirm_ajax(request):
if request.method != 'POST':
raise Http404
try:
data = json.loads(request.body)
file_data = json.loads(data[0])
head, content = file_data['file'].split(',')
@@ -83,6 +85,11 @@ def change_avatar_confirm_ajax(request):
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})