Why do i get this error "cannot unpack non-iterable bool object"
i get this error "cannot unpack non-iterable bool object" as i try to get user input from a form in django which in this case is an email
def send_email(request):
recepient_list=[]
if request.method == "POST":
email = request.POST['pwd_email']
print(email)
if User.objects.filter(email == email).exists:
recepient_list.append(email)
send_mail("PASSWORD RESET", f"Your password resetkey is {random_no} \n Do not share this key with anyone", "eliaakjtrnq@gmail.com",recepient_list,fail_silently=False,)
recepient_list.clear()
The line that I believe is giving you some trouble is:
if User.objects.filter(email == email).exists:
There are two issues that I see:
- You should being using an assignment "=" rather than a check for equality "=="
- I believe
eixsts()is a method, not an attribute so you need to include the "()"
Try changing that line to:
if User.objects.filter(email=email).exists():
and see if your error still persists.
There are several problems here, the main one is .filter(email == email). This will check if the string is equal to itself, and therefore always True, you thus use .filter(True), and Django can of course not do much with the bool.
You should filter with:
def send_email(request):
recepient_list = []
if request.method == 'POST':
email = request.POST['pwd_email']
print(email)
# ***call*** .exists() 🖟
if User.objects.filter(email=email).exists():
recepient_list.append(email)
send_mail(
'PASSWORD RESET',
f"Your password resetkey is {random_no} \n Do not share this key with anyone",
'eliaakjtrnq@gmail.com',
recepient_list,
fail_silently=False,
)
recepient_list.clear()