I have a form with only the email label for the user to fill out. If the email already exists I want to redirect it to the edit page. How do I get the user id through the email he typed? I did a test as shown below with id 14 and is going to the right page, I just have to figure out how to get the id.
def email(request):
form = EmailForm(request.POST or None)
if form.is_valid():
email = form.cleaned_data.get("email")
try:
profile = Perfil.objects.get(email=email, is_staff=False)
print("email ja existe e nao staff")
return redirect("cadastro:editar", id=profile.id)
except:
if not Perfil.objects.filter(email=email).exists():
print("novo usuario")
return redirect("/cadastro/cadastro")
else:
print("já entra no sistema")
return redirect("/cadastro/login")