Backend Technologies · Python
Flask — Free Learning Resources
Free, printable resources for Flask — practice problems, quick-reference cheatsheet, and an interview prep sheet. No sign-up required.
Flask — Practice Worksheet
Structured exercises and problems to build hands-on Flask skills. Work through key concepts step by step.
Flask — Cheatsheet
One-page quick-reference for Flask — key syntax, commands, patterns, and best practices at a glance.
Flask — Interview Sheet
Top Flask interview questions with concise answers. Get ready for any technical round with this focused prep sheet.
About Flask
Flask is a lightweight WSGI Python web framework designed to make getting started quick and easy. Its minimalist core — routing, request handling, templating — gives developers full control over which components to add. Flask is widely used for REST APIs, prototypes, and microservices where Django's batteries would be unnecessary overhead.
FlaskCheat Sheet — What's Covered
- ✓Application factory pattern and Blueprint-based modular routing
- ✓Request context, application context, and the g object
- ✓Flask-SQLAlchemy ORM integration and migrations with Alembic
- ✓Flask-RESTful and Marshmallow for API validation and serialization
- ✓Error handling, before/after request hooks, and custom error pages
Frequently Asked Questions — Flask
What is the difference between Flask's application context and request context?
The request context (per HTTP request) provides the request and session proxies. The application context provides current_app and g. g is a per-request namespace reset each request — use it to store resources like database connections opened in before_request.
How do you structure a large Flask application?
Use Blueprints to split the app into modules (auth, api, admin). Each blueprint owns its routes, templates, and static files. Wire everything together in a create_app() factory function to enable multiple app instances for testing.
How does Flask handle database connections with SQLAlchemy?
Flask-SQLAlchemy binds SQLAlchemy to the Flask app context. db.session is scoped to the request — it's automatically committed or rolled back at request end. Use db.init_app(app) with the factory pattern to avoid circular imports.
How do you create a REST API with Flask?
Use @app.route('/users/<int:id>', methods=['GET','PUT','DELETE']) and return jsonify(data). For larger APIs, Flask-RESTful adds Resource classes; Flask-Smorest adds OpenAPI schema generation and request validation via Marshmallow.
How do you handle errors in Flask?
Use @app.errorhandler(404) to register handlers for HTTP error codes. Call abort(404) from routes to trigger them. For JSON APIs, return jsonify({'error': 'Not found'}), status_code consistently. Register a catch-all @app.errorhandler(Exception) for unexpected errors.
Who Is This For?
Python developers who prefer a minimal framework and want to choose their own database, ORM, and auth libraries rather than accepting framework defaults.