flask如何实现将当前URL的数据(提交表单从数据库获取的),传递给重定向的URL

1.当前sql.html界面提供一个表单,提供数据库服务器名和表名,Post后路由函数执行cursor.execute()查询语句,将查询的数据在result.html中展示,我使用的是
return render_template('result.html',table=table,infos=infos)方法显示
2.现在我想给result.html写一个路由,通过return redirect(url_for('result.html))方法,重定向到result.html界面,数据该如何传递过去
3.当前实现代码如下,请各位大神指点一下


@main.route('/sql',methods=['GET', 'POST'])
def sql():
    if not current_user.is_authenticated:
        flash('Please login first')
        return redirect(url_for('auth.login'))
    form=SQLForm()
    if form.validate_on_submit():
        database = form.Servername.data
        table = form.Tablename.data
        host = re.findall(r"\d+", database)
        host_login = '.'.join(host)
        oracle = cx_Oracle.connect('..../...@%s:1521/...' % host_login)
        cursor = oracle.cursor()
        infos = cursor.execute('select * from %s' % table).fetchall()
        columnslen = len(infos[0])
        columnsname = cursor.execute("select COLUMN_NAME from user_tab_columns where TABLE_NAME='%s'" %table.upper() ).fetchall()
        oracle.commit()
        cursor.close()
        oracle.close()
        return render_template('result.html',table=table,infos=infos,columnslen=columnslen,columnsname=columnsname)    #如果使用url_for该如何将数据传递过去
    return render_template('sql.html',form=form)


#@main.route('/result')
#def result():
#return render_template('result.html')
阅读 3.8k
1 个回答

传参数到result.html,处理

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题