I have a python flask server. In the main of my script, I get a variable from user that defines the mode of my server. I want to set this variable in main (just write) and use it (just read) in my controllers. I am currently using os.environ, but I 'm searching for more flasky way to use.
I googled and tried following options:
flask.g: it is being reset for each request; so, I can't use it inside controllers when it is being set somewhere else.flask.session: it is not accessible outside request context and I can't set it in the main.Flask-Session: like the second item, I can't set it in themain.
In
mainyou useapp.run()soappis avaliable inmain. It should be also avaliable all time in all functions so you can try to usebut flask has also
to keep any settings. See doc: Configuration Handling