Reputation: 195
I dont know how to check for empty results from a cursor.execute. Say I have a empty table Brand. I do:
cursor.execute("SELECT * FROM Brand")
db.commit()
results = cursor.fetchall()
return render_template("index.html", results = results)
and this pops up on the website:
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
Wanted a fix, maybe a if statement to check if the results are empty..
Upvotes: 0
Views: 1272
Reputation: 11
You can use
if cursor.rowcount == 0 # empty results
And you don't need db.commit()
as mentioned in the comments.
Upvotes: 1