基本上,在应用程序中,我连接到sql数据库,并尝试检索用户输入的结果,这些输入是AGE
、SEX
和{
我可以为用户输入年龄和SEX
,并获得所需的结果,但当我为AGE
、SEX
和{NONE
值。在
Python代码:
import MySQLdb
from flask import Flask, render_template, request
from flask.ext.mysqldb import MySQL
app = Flask(__name__)
db = MySQLdb.connect("127.0.0.1","root","","health" )
@app.route("/", methods = ['GET','POST'])
def home():
return render_template('home.html')
@app.route("/value", methods = ['GET','POST'])
def Authenticate():
cursor = db.cursor()
AGE = request.form['AGE']
SEX = request.form['SEX']
ADMITTING_DIAGNOSIS_CODE = request.form['ADMITTING_DIAGNOSIS_CODE']
#DIAGNOSIS_CODE_1= request.args['DIAGNOSIS_CODE_1']
sql = 'select avg(LENGTH_OF_STAY),avg(TOTAL_CHARGES),(select count(*) from health where AGE = %s and SEX = %s and ADMITTING_DIAGNOSIS_CODE = %s and DISCHARGE_STATUS = "A")/(count(*))*100 as alive,(select count(*) from health where AGE = %s and SEX = %s and ADMITTING_DIAGNOSIS_CODE = %s and DISCHARGE_STATUS = "B")/(count(*))*100 as dead from health where AGE = %s and SEX = %s and ADMITTING_DIAGNOSIS_CODE = %s'
entries = []
cursor.execute(sql,(AGE,SEX,ADMITTING_DIAGNOSIS_CODE,AGE,SEX,ADMITTING_DIAGNOSIS_CODE,AGE,SEX,ADMITTING_DIAGNOSIS_CODE,))
# Fetch all the rows in a list of lists.
results = cursor.fetchall()
for row in results:
entries.append(dict([('avg(LENGTH_OF_STAY)',row[0]),
('avg(TOTAL_CHARGES)',row[1]),
('dead',row[3]),
('alive',row[2])
]))
return render_template('show_entries.html', entries=entries)
if __name__ == "__main__":
app.debug = True
app.run()
HTML代码:
^{pr2}$输出:
Length of stay Total charge Alive Dead
None None None None
目前没有回答
相关问题 更多 >
编程相关推荐