Rumah > Soal Jawab > teks badan
1、定义的路由
@main.route('/qqsql',methods=['GET','POST'])
def qqsql():
cmdsql = None
commandform = CommandForm()
serverlists = GameServer.query.all()
if commandform.validate_on_submit():
# global dbname
session['cmdsql'] = commandform.command.data
session['serverID'] = request.form.getlist('dbcheckbox')
for db in session.get('serverID'):
dbsql = GameServer.query.filter_by(serverId=db).first()
dbhost = dbsql.serverHost
dbname = dbsql.serverName
session['sqlres'] = runSql(dbhost=dbhost,serverid=db,sql=session.get('cmdsql'))
print session.get('sqlres')
return redirect(url_for('main.owsql'))
return render_template('owsql.html',
commandform=commandform,
cmdsql=session.get('cmdsql'),
serverlists=serverlists,
sqlres = session.get('sqlres'),
dbname = dbname <=====问题出现在这里
)
注意dbname 的值,现在想把dbname 的值也返回到页面怎么处理?
黄舟2017-04-17 17:31:37
@main.route('/qqsql', methods=['GET','POST'])
def qqsql():
cmdsql = None
commandform = CommandForm()
serverlists = GameServer.query.all()
data = {
"commandform": commandform,
"serverlists": serverlists
}
if commandform.validate_on_submit():
# global dbname
session['cmdsql'] = commandform.command.data
session['serverID'] = request.form.getlist('dbcheckbox')
for db in session.get('serverID'):
dbsql = GameServer.query.filter_by(serverId=db).first()
dbhost = dbsql.serverHost
dbname = dbsql.serverName
sqlres = runSql(dbhost=dbhost,serverid=db,sql=session.get('cmdsql'))
session['sqlres'] = sqlres
print session.get('sqlres')
data.update(dbname=dbname, sqlres=sqlres)
return redirect(url_for('main.owsql'))
return render_template('owsql.html', **data)
hanya perlu dihantar ke halaman apabila dbname
wujud, jika tidak dbname
tetapkan nilai lalai