-1

I want to change the value of the variable named "er" outside of the flask route with the request to the flask route. However, it does not change.Do you think there is a way to do this?

er = 1
@app.route('/api/get' ,methods=['GET'])
def first_get():
    er = 2
    return 'First GET'

print("er:",er)

Output: er: 1

print("er:",er)

Output I want it to be: er: 2

sabcan
  • 407
  • 3
  • 15

1 Answers1

0

You can use the global keyword, see https://docs.python.org/3/reference/simple_stmts.html#global.

er = 1
@app.route('/api/get' ,methods=['GET'])
def first_get():
    global er
    
    er = 2
    return 'First GET'

print("er:",er)
Simeon Nedkov
  • 1,097
  • 7
  • 11