How can I take input from url in flask from the parameter?
JavaScript
x
5
1
@app.route('/<id>')
2
def give_id(id):
3
4
return id
5
I need to take the above Id from input and pass it to other function without again needing to write "id"
JavaScript
1
4
1
def some_function():
2
variable1 = vid_stream.get_hls_url(give_id("I need to again pass that Id here"))
3
4
How can I directly use the id from give_id(id)
function and feed it into vid_stream.get_hls_url
function?
Posting complete demo code, In case someone needs to run locally.
JavaScript
1
16
16
1
from flask import Flask
2
app = Flask(__name__)
3
4
@app.route('/<id>')
5
def give_id(id):
6
7
return id
8
9
def some_function():
10
variable1 = vid_stream.get_hls_url(give_id("I need to again pass that Id here"))
11
print(variable1)
12
some_function()
13
14
if __name__ == '__main__':
15
app.run(host='0.0.0.0',port=8080)
16
Advertisement
Answer
This should work. id
is reserved keyword so i have renamed it you can call the function by passing the value. You can call some_function
from you give_id
view directly.
JavaScript
1
18
18
1
from flask import Flask
2
app = Flask(__name__)
3
4
def some_function(p_id):
5
variable1 = vid_stream.get_hls_url(give_id("I need to again pass that Id here"))
6
print(variable1)
7
return variable1
8
9
@app.route('/<id>')
10
def give_id(p_id):
11
output = some_function(p_id)
12
return p_id
13
14
15
16
if __name__ == '__main__':
17
app.run(host='0.0.0.0',port=8080)
18