I am going to set some data in a global variable once "/setvalue" route is called.
Then whoever wants to retrieve this data(even from outside of the web app, browser) can access it.
The problem is the call for retrieving the data comes from outside, e.g. a client who hits the URL from any browser can get this data
I have tried using "g" as follow, but it is not working:
from flask import g
@app.route("/setvalue", methods = ['POST'])
def setvalue():
content = request.get_json()
g.content = content
return format(content) #"set"
@app.route("/getvalue" )
def getvalue():
return g.content
from flask import Flask, jsonify, request
from flask import g
As the above code show, I will call "/setvalue" to initiate the web app.
And whoever calls "/getvalue" will get the value that was initiated.
But g.content doesn't seem to work this way. I received a 500 error.
What is missing from my code? Thanks in advance. Your help would be greatly appreciated