Understanding app.run(debug=True) in Flask

 

 app.run(debug=True) 

In our previous example, we started the Flask application using:

app.run(debug=True)

The app.run() method starts Flask's built-in development web server. Once the server starts, the application becomes accessible in a web browser, typically at:

http://127.0.0.1:5000

The debug=True parameter enables Debug Mode, which is very useful during development.

Benefits of Debug Mode

  • Automatically reloads the application whenever you save changes to your Python file. You don't need to stop and restart the server manually.

  • Displays detailed error messages in the browser if your application encounters an error, making it much easier to identify and fix problems.

  • Speeds up development, allowing you to test changes quickly.

Note: Debug mode should only be used during development. It should be disabled (debug=False) before deploying your Flask application to a production environment for security reasons.

Example

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello Pranay, There'

@app.route('/pranay')
def text_info():
    return 'Hey there, Flask tutorial begins'

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

When you run this program, Flask starts a local web server in debug mode. Any changes you make to the code are automatically reflected after saving the file, making development faster and more convenient.



Uploading: 96383 of 96383 bytes uploaded.




Let me change the code and save it 




just refresh the URL http://127.0.0.1:5000/






Post a Comment

0 Comments