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 的值也返回到页面怎么处理?
应该只在
dbname
存在时才向页面传,要不然就然dbname
设置一下默认值