为什么我得到错误的用烧瓶计数的输出格式?
Why I get the wrong output format of counting with flask?
我现在正在尝试计算 phpMyAdmin 数据库中的数据数量。为什么我会得到像 (2,) 这样的输出,而不是像 2 这样的数字格式?
app.py代码
@app.route("/adminPanel", methods=['GET', 'POST'])
def adminPanel():
if 'adminName' in session:
cur = mysql.connection.cursor()
result1 = cur.execute("SELECT COUNT(*) FROM adminaccount")
display2 = cur.fetchone()
cur.close()
adminName = session['adminName']
return render_template("adminPanel.html", adminName=adminName, result1=result1, display2=display2)
else:
return redirect(url_for('adminLogin'))
结果
result of the output
Select returns 结果,每个结果都是一个值元组。您的 select 只要求一个值,因此您将得到一个只有一个值的元组。所以:
display2 # this is the whole row
display2[0] # this is the value of the first "column"
因此,在处理每行 1 列和每行更多列时,您拥有相同的界面。
我现在正在尝试计算 phpMyAdmin 数据库中的数据数量。为什么我会得到像 (2,) 这样的输出,而不是像 2 这样的数字格式?
app.py代码
@app.route("/adminPanel", methods=['GET', 'POST'])
def adminPanel():
if 'adminName' in session:
cur = mysql.connection.cursor()
result1 = cur.execute("SELECT COUNT(*) FROM adminaccount")
display2 = cur.fetchone()
cur.close()
adminName = session['adminName']
return render_template("adminPanel.html", adminName=adminName, result1=result1, display2=display2)
else:
return redirect(url_for('adminLogin'))
结果 result of the output
Select returns 结果,每个结果都是一个值元组。您的 select 只要求一个值,因此您将得到一个只有一个值的元组。所以:
display2 # this is the whole row
display2[0] # this is the value of the first "column"
因此,在处理每行 1 列和每行更多列时,您拥有相同的界面。