1
I have a form with only the email label for the user to fill. If the email already exists I want to redirect it to the edit page. How do I get the user id from the email he typed? I did a test as shown below with id 14 and is passing 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")
The filter returns a Queryset, there is no way to get the id using filter, gives the following error: 'Queryset' Object has in attribute 'id'
– Bianca C.
Sorry. I changed the code above. I switched . filter with . get
– Marcos Felipe
Really. get returns an Exception if the object does not exist. I changed the above code one more time to adjust the Exception.
– Marcos Felipe
I got Marcos! Thanks for the help! I changed the code the way it was!!
– Bianca C.