Is it possible to use a URL variable inside the function in flask? I have searched extensively and have not gotten any wiser.
If I display pathVariable in the html template it displays whatever I would type in.
from flask import Flask, request
app = Flask(__name__)
@app.route('/<pathVariable>/')
def test(pathVariable=pathVariable):
test = pathVariable
path = request.path
script_root = request.script_root
base_url = request.base_url
url = request.url
url_root = request.url_root
url_rule = request.url_rule
print ("test is: %s" %path)
print ("path is: %s" %path)
print ("script_root is: %s" %script_root)
print ("base_url is: %s" %base_url)
print ("url is: %s" %url)
print ("url_root is: %s" %url_root)
print ("url_rule is: %s" %url_rule)
return render_template('/example.html', pathVariable=pathVariable)
if __name__ == '__main__':
app.run()
For example if I type in :
127.0.0.1:5000/tryone and 127.0.0.1:5000/trytwo, the pathVariable would be rendered as tryone or trytwo within the html template.
But inside the test function the printout I get is:
test is: /favicon.ico/
path is: /favicon.ico/
script_root is:
base_url is: http://http://127.0.0.1:5000/favicon.ico/
url is: http://http://127.0.0.1:5000/favicon.ico/
url_root is: http://http://127.0.0.1:5000/
url_rule is: /<pathVariable >/
I there any way that I could get tryone or trytwo inside the test function?
I have a dictionary with lists associated to each of these variables, and they determine what variables must be returned (rendered) back to the html template.
pathvariablein the functiondef test(pathVariable=pathVariable):- should this not simply bedef test(pathVariable):