from pprint import pprint from django.contrib.auth import logout from django.http import HttpResponseRedirect from django.shortcuts import render, redirect from django.urls import reverse from users.forms import UserMetaForm from users.models import CustomUser def profile(request): if request.method == "POST": if not request.user.is_authenticated: return HttpResponseRedirect(reverse("users:profile")) form = UserMetaForm(request.POST, instance=request.user) if form.is_valid(): form.save() return HttpResponseRedirect(reverse("users:profile")) else: form = UserMetaForm(instance=request.user) if request.user.is_authenticated else None return render(request, "users/profile.html", {"form": form}) def logout_view(request): logout(request) return redirect(reverse("users:profile"))