I'm trying to get the url of a webpage and store it as a variable, so that I can use that variable in a separate python program.
I'm new to flask, but I'm pretty sure that the commented code below can only work locally... I can't think of a way to make a global variable.
import random
from io import BytesIO
from flask import Flask, make_response,Response,request
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
import matplotlib.pyplot as plt
app = Flask(__name__)
@app.route('/')
def plot():
fig, ax = plt.subplots(1,1,figsize=(16,5))
ax.plot(range(100), [random.randint(1, 50) for x in range(100)])
canvas = FigureCanvas(fig)
output = BytesIO()
canvas.print_png(output)
response = make_response(output.getvalue())
response.mimetype = 'image/png'
return response
# var = request.root_url
if __name__ == '__main__':
app.run(debug=True)
EDIT: Moderators, as I have said, I wanted to use the variable in another program. NOT necessarily between flask pages. Ergo, this is not a duplicate.