0
0
Flaskframework~5 mins

Development server with debug mode in Flask

Choose your learning style9 modes available
Introduction

Debug mode helps you find and fix errors quickly while you build your web app. The development server restarts automatically when you change your code.

When you are building a new Flask web app and want to see changes immediately.
When you want detailed error messages to understand what went wrong.
When you want the server to reload automatically after you edit your code.
When testing new features before making your app live.
When you want to avoid restarting the server manually after every change.
Syntax
Flask
app.run(debug=True)
Use debug=True inside app.run() to turn on debug mode.
Do not use debug mode in production because it can show sensitive information.
Examples
This example starts the Flask app with debug mode on. The server reloads on code changes and shows detailed errors.
Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return 'Hello, Flask!'

if __name__ == '__main__':
    app.run(debug=True)
This runs the server without debug mode. Changes won't reload automatically and errors are less detailed.
Flask
app.run(debug=False)
Sample Program

This program creates a simple Flask app that shows a welcome message. Running it with debug=True means you get live reloads and helpful error messages.

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return 'Welcome to debug mode!'

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

Debug mode shows detailed error pages with helpful info.

Auto-reloading saves time by restarting the server when you save files.

Never use debug mode on a public or production server for security reasons.

Summary

Debug mode helps you develop faster by showing errors and reloading automatically.

Enable it by passing debug=True to app.run().

Turn it off before deploying your app to keep it safe.