Pass multiple variables between pages to the html url from flask

Question:

I need to pass two variables in the url from one html page to another. It turned out to pass one "name" and it looks like: http://localhost/push_web?service_name=test

But I need to pass it so that it turns out something like: http://localhost/push?name=test&token=21hgsgwqyqy8218gddsyqwaw22

But this does not work, only the name variable is passed to the url, and the token is written to the cell as None. What am I doing wrong? Or is it impossible to do this in HTML?

My code what have I tried:

flask:

session['name'] = name
session['token'] = token           
return redirect(url_for('push_web'))
@app.route('/push')
def push():
    name = request.args.get('name', None)
    token = request.args.get('token', None)
    return render_template("push.html", name=request.args.get('name', None), token=request.args.get('token', None))

in html:

<a href="{{ url_for('push', name=name, token=token ) }}">Page</a>

I was expecting a page like: http://localhost/push?name=test&token=21hgsgwqyqy8218gddsyqwaw22

But I only succeeded: http://localhost/push?name=test

Asked By: MedStream

||

Answers:

This is how it is intended to work:

@app.route('/push')
def push():
    name = session.get('name', None)
    token = session.get('token', None)
    return render_template("push.html", name=name, token=token)
Answered By: Tim Roberts

I found the solution myself, in my case it worked like this:

Flask(Python):
I take the variables from here:

   session['name'] = name
   session['token'] = token           
   return redirect(url_for('push'))

I put variables here here:

@app.route('/push') 
   def push():     
       name = request.args.get('name', None)     
       token = request.args.get('token', None)     
       return render_template("push.html", name=name, token=token)

HTML:

<a href="{{ url_for('push', name=name, token=token ) }}">Page</a>

Result: http://localhost/push?name=test&token=21hgsgwqyqy8218gddsyqwaw22

Answered By: MedStream
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.