Home > Enterprise >  How to run server in development mode with flask?
How to run server in development mode with flask?

Time:09-30

I am learning to use flask and I want to run the server for an application in development mode, for this I do the following:

app = Flask(__name__)
if __name__=="__main__":
    os.environ["FLASK_ENV"] = "development"
    app.run(debug=True) 

When I run I get the following in the terminal: enter image description here

Environment:development does not appear to me as I understand it should appear. In fact, before doing this I don't get Environment:production either, I don't know what's going on. As a consequence, every time I want to see the changes that I am making in the code, I have to stop the server and run it again since the changes are not seen when refreshing the page.

CodePudding user response:

If you're goal is for the application to restart each time code changes are saved, it shouldn't require any more than the following:

app = Flask(__name__)

if __name__=="__main__":
    app.run(debug=True) 

If you want to see what all your app config variables are set to by default, you can add the following line above app.run

print(app.config)

If you wanted to change your environment to production, change the 'ENV' variable after you initialize app

app = Flask(__name__)
app.config['ENV'] = 'production'

if __name__=="__main__":
    app.run(debug=True) 
  • Related