I am working on Project 1 for CS50W on EdX. I am building the book search Flask app. My problem is with building the SQL SELECT statement utilizing the WHERE clause depending on the search fields.

I tried checking whether text field in form is empty, but regardless of the input Python doesn't consider the field empty.

title = request.form.get("title")

if title is None:
    result = "Empty"
    result = "Not Empty"

Whether I input a value into title, the result I get is always "Not Empty". Is there another way to check whether the user typed anything in?


Welcome to the forum!

If the user doesn't type anything in, title will be an empty string (ie ""), not None. The empty string is "falsy" so you can use if not title.

  • Thank you. I was able to get around this issue by using len(title) > 0 Sep 15 '18 at 11:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .