-3

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Diego L
  • 185
  • 1
  • 9

1 Answers1

0

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) 
Andrew Clark
  • 850
  • 7
  • 13
  • Thank you very much. It's my first question in this community, I didn't expect to get help so quickly. Do you have any idea why it doesn't record the changes I make to other urls? Only in the main. Again, thank you very much for your time. – Diego L Sep 29 '22 at 19:35
  • @DiegoL Can you provide an example, and/or farther explain what you mean? I'm not quite following your question "why it doesn't record the changes I make to other urls"? Also, if you need to post any additional code, you can just click edit on your original question, and add addition content below your original post. Typically just type something like "Edit 1:", and post additional info below that point. – Andrew Clark Sep 29 '22 at 20:01
  • and you're welcome :) tbh you just got lucky that you got a quick response. Most questions from new members go unanswered for a variety of reasons. Happy to help though. Also, To mark an answer as accepted, click on the check mark beside the answer to toggle it from greyed out to filled in. Here is a link describing in more detail what you should do when someone answers your question: https://stackoverflow.com/help/someone-answers#:~:text=To%20accept%20an%20answer%3A,the%20answer%2C%20at%20any%20time – Andrew Clark Sep 29 '22 at 20:02