How do you create a basic Flask application?

Why Interviewers Ask This

This is a classic screening question for FastAPI / Flask roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

Create a Flask app in minimal code: from flask import Flask; app = Flask(__name__); @app.route('/') def home(): return 'Hello World'; if __name__ == '__main__': app.run(debug=True). The Flask(__name__) creates the app instance — __name__ tells Flask where to look for templates and static files. @app.route('/') registers the function as the handler for GET /. app.run(debug=True) starts the development server with auto-reload. For production, use Gunicorn: gunicorn app:app -w 4. The Flask application object is the central point — you register routes, configure extensions, and create the WSGI callable through it. __name__ is important: it helps Flask find your package resources relative to the file.

Common Mistake

Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex FastAPI / Flask answers easy to follow.