I want to assign the data from the request to the variable currentKampjson that is used multiple places in the code. But when I try to assign currentKampjson to anything it gets declared as a new variable, this applies to every variable.
currentKampjson is a dictionary type variable
currentKampjson = {"info":1, "info2":3}
@app.route("/stream/currentkamp")
def streamCurrentKamp():
return render_template("stream/currentKamp.html", kamp = currentKampjson)
@app.route("/currentKamp/getKamp")
def getCurrentKamp():
return jsonify(currentKamp)
print(currentKampjson)
@app.route("/currentKamp/update", methods=["POST"])
def updateCurrentKamp():
indata = eval(request.data)
currentKampjson = indata
with open("jsonFiles/kamper/currentKamp.json","w") as f:
json.dump(indata, f)
return "SUCCESS"
This code runs fine, even though I am using currentKampjson here:
@app.route("/currentKamp/update", methods=["POST"])
def updateCurrentKamp():
indata = eval(request.data)
print(currentKampjson)
#currentKampjson = indata
with open("jsonFiles/kamper/currentKamp.json","w") as f:
json.dump(indata, f)
return "SUCCESS"
question from:
https://stackoverflow.com/questions/65941738/python-variable-is-declared-and-still-gives-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…