def profile_edit(request):
profile = Profile.objects.get(user=request.user)
if request.method == 'POST':
userform = UserUpdateForm(request.POST,instance=request.user)
profileform = ProfileUpdateForm(request.POST,request.FILES,instance=profile)
if userform.is_valid and profileform.is_valid:
userform.save()
new_profile = profileform.save(commit=False)
new_profile.user = request.user
new_profile.save()
return redirect('/accounts/profile')
else:
userform = UserUpdateForm(instance=request.user)
profileform = ProfileUpdateForm(instance=profile)
return render(request,'accounts/profile_edit.html',context={'form1':userform,'form2':profileform})