1

I want to open a new page in a new tab (Similar to window.open) using flask webApp and also pass parameters from the parent page to the child window and based on those parameters get data from database and show on the child window

<title> Parent Page </title>
window.open('child.html') // pass parameters parameter1, parameter2

Flask Code:

@app.route('/')
def renderParentPage():
    return render_template('parentPage.html')


@app.route('/<string:page_name>/')
def render_static(page_name):
    print('%s' % page_name)
    dataTosend = getBrandData("Parameters from parent page- parameter1, parameter2")
    return render_template('%s' % page_name, dataToSend=dataTosend)
Sahil Sahni
  • 43
  • 1
  • 4
  • 1
    Check this out: https://stackoverflow.com/questions/19127434/flask-redirect-new-tab – AimiHat Jun 28 '18 at 23:01
  • 1
    Possible duplicate of [Flask Redirect New Tab](https://stackoverflow.com/questions/19127434/flask-redirect-new-tab) – AimiHat Jun 28 '18 at 23:01
  • It only talks about opening a new page. That I can easily achieve with window.open() as well in javascript. My main issue is how to work with parameters to and fro from server between parent page and the server and from server to new tab – Sahil Sahni Jun 28 '18 at 23:11

1 Answers1

1

In order to pass parameters to the child page, you can format it as a GET request:

window.open('/child?param1=value1&param2=value2')

And then use request.args to get parsed contents of query string:

from flask import request

@app.route(...)
def login():
    username = request.args.get('username')
    password = request.args.get('password')

    #Do something with parameters

    return render_template([...])
AimiHat
  • 383
  • 4
  • 14