1. What is Flask?
BeginnerAnswer: Lightweight Python web framework
Flask is a lightweight Python web framework created by Armin Ronacher. It's a micro-framework that provides essential tools without forcing specific patterns.
24 questions that come up in Flask technical interviews, each with the answer and an explanation of why it is right.
Test yourself — 90 question bankAnswer: Lightweight Python web framework
Flask is a lightweight Python web framework created by Armin Ronacher. It's a micro-framework that provides essential tools without forcing specific patterns.
Answer: Extension for building REST APIs
Flask-RESTful simplifies REST API development. Provides Resource classes, request parsing, response marshalling. Alternative to plain Flask for APIs.
Answer: Extension integrating SQLAlchemy ORM with Flask
Flask-SQLAlchemy is extension integrating SQLAlchemy ORM. Simplifies database operations, provides helpful utilities. Install: pip install flask-sqlalchemy.
Answer: Class inheriting from db.Model
Define models as classes inheriting from db.Model. Define columns as class attributes: id = db.Column(db.Integer, primary_key=True). Represents database table.
Answer: Extension for JWT authentication and authorization
Flask-JWT-Extended provides JWT authentication. Features: token creation, verification, refresh tokens, blacklisting. Use @jwt_required decorator for protected routes.
Answer: Provides core features, extensible via extensions
Flask is "micro" because it keeps the core simple but extensible. Doesn't include database abstraction, form validation by default - add via extensions.
Answer: Stores expensive operation results for reuse
Caching stores expensive operation results. Use Flask-Caching. Backends: simple, redis, memcached. Cache views, query results. Dramatically improves performance.
Answer: app = Flask(__name__)
Create Flask app: app = Flask(__name__). The __name__ parameter helps Flask locate resources. This creates the application instance.
Answer: Database schema version control
Migrations are version control for database schema. Track changes over time. Use Flask-Migrate (Alembic wrapper). Run flask db migrate, flask db upgrade.
Answer: Extension providing caching support
Flask-Caching adds caching support. Multiple backends: simple (memory), redis, memcached, filesystem. Use @cache.cached() decorator. Set timeout, key prefix.
Answer: URL pattern mapped to function
A route maps URL patterns to view functions. Use @app.route() decorator. Example: @app.route('/home') defines route for /home URL.
Answer: Extension for forms with validation and CSRF protection
Flask-WTF integrates WTForms with Flask. Provides form validation, CSRF protection, file uploads. Define forms as classes inheriting from FlaskForm.
Answer: Distributed task queue for background jobs
Celery is distributed task queue. Runs background jobs asynchronously. Use for emails, processing, scheduled tasks. Requires message broker (Redis, RabbitMQ).
Answer: @app.route('/path')
Define routes with @app.route() decorator above view function. Example: @app.route('/about') def about(): return 'About page'.
Answer: form.validate_on_submit()
Validate forms with form.validate_on_submit(). Returns True if POST request and validation passes. Access errors with form.field.errors.
Answer: Configure Celery with Flask app context
Integrate Celery: create Celery instance, configure broker, create tasks with @celery.task. Run worker: celery -A app.celery worker. Requires app context for Flask features.
Answer: All of the above
Multiple ways: flask run (recommended), python app.py (with app.run()), or python -m flask run. Set FLASK_APP environment variable.
Answer: Organizes app into components/modules
Blueprint organizes large apps into components. Each blueprint can have own routes, templates, static files. Register with app.register_blueprint(). Supports modular development.
Answer: bp = Blueprint('name', __name__)
Create Blueprint: bp = Blueprint('auth', __name__). Register routes with @bp.route(). Register blueprint: app.register_blueprint(bp, url_prefix='/auth').
Answer: Function handling request and returning response
View function handles requests and returns responses. Decorated with @app.route(). Can return string, render template, or Response object.
Answer: Limits request rate to prevent abuse
Rate limiting restricts requests per time period. Use Flask-Limiter. Prevent abuse, DDoS. Configure per route: @limiter.limit("100 per hour"). Use Redis for distributed systems.
Answer: Extension for WebSocket support
Flask-SocketIO adds WebSocket support. Enables real-time bidirectional communication. Use for chat, notifications, live updates. Based on Socket.IO.
Answer: Extension for user session management
Flask-Login manages user sessions. Provides login/logout, current_user, login_required decorator. User model must implement UserMixin or required methods.
Answer: Renders HTML template with Jinja2
render_template() renders HTML templates using Jinja2 engine. Pass template name and variables: render_template('index.html', title='Home').
The full Flask bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.
Take the Flask quiz