from django.shortcuts import render from django.contrib.auth.decorators import login_required from .forms import ProfileForm, UserForm @login_required def profile(request): success = False user = request.user if request.method == "POST": user_form = UserForm(request.POST, instance=user) profile_form = ProfileForm(request.POST, instance=user.profile) if all((user_form.is_valid(), profile_form.is_valid())): user_form.save() profile_form.save() success = True else: user_form = UserForm(instance=user) profile_form = ProfileForm(instance=user.profile) return render(request, "gestion/profile.html", {"user_form": user_form, "profile_form": profile_form, "success": success})