Jan-05-2020, 04:20 PM
Well this is what I came up with to work. Probably not the best solution but, I'm learning more.
Used the os.path.isfile for testing then took it out.
Used the os.path.isfile for testing then took it out.
@login_required def edit_profile(request): curr_img = request.user.profile.image.url # Getting the current image if request.method == 'POST': if request.POST.get('image') == '': #Checking to see if the user changed image or left blank pass else: os.remove('/path/to/top/level/folder' + str(curr_img)) # What I had to use to get the old file removed u_form = UserUpdateForm(request.POST, instance=request.user) p_form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.profile) if u_form.is_valid() and p_form.is_valid(): u_form.save() p_form.save() messages.success(request, 'Your profile has been updated.') return redirect('profile') else: u_form = UserUpdateForm(instance=request.user) p_form = ProfileUpdateForm(instance=request.user.profile) context = { 'u_form': u_form, 'p_form': p_form, } return render(request, 'users/edit_profile.html', context)
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags