I'm new on flask.I configured a server with flask+gunicorn.
the code file called test.py
like this:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def test():
return aa+"world!"
if __name__ == '__main__':
aa = "hello"
app.run()
run it using:gunicorn -b 0.0.0.0:8080 test:app
I got a mistake:NameError: name 'aa' is not defined.
I want some codes like variable aa
runing before gunicorn.
How to do that?
Put in a small block just before your @app.route
and you dont need the last block in the question
@app.before_first_request
def _declareStuff():
global aa
aa='hello'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With