All interview guides

Flask Interview Questions and Answers

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 bank

1. What is Flask?

Beginner

Answer: 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.

2. What is Flask-RESTful?

Advanced

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.

3. What is Flask-SQLAlchemy?

Intermediate

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.

4. How do you define a model?

Intermediate

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.

5. What is Flask-JWT-Extended?

Advanced

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.

6. Why is Flask called a micro-framework?

Beginner

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.

7. What is caching in Flask?

Advanced

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.

8. How do you create a Flask app?

Beginner

Answer: app = Flask(__name__)

Create Flask app: app = Flask(__name__). The __name__ parameter helps Flask locate resources. This creates the application instance.

9. What is a migration?

Intermediate

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.

10. What is Flask-Caching?

Advanced

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.

11. What is a route in Flask?

Beginner

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.

12. What is Flask-WTF?

Intermediate

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.

13. What is Celery?

Advanced

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).

14. How do you define a route?

Beginner

Answer: @app.route('/path')

Define routes with @app.route() decorator above view function. Example: @app.route('/about') def about(): return 'About page'.

15. How do you validate forms?

Intermediate

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.

16. How do you integrate Celery with Flask?

Advanced

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.

17. How do you run a Flask app?

Beginner

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.

18. What is Blueprint?

Intermediate

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.

19. How do you create a Blueprint?

Intermediate

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').

20. What is a view function?

Beginner

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.

21. What is rate limiting?

Advanced

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.

22. What is Flask-SocketIO?

Advanced

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.

23. What is Flask-Login?

Intermediate

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.

24. What does render_template() do?

Beginner

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').

Ready to test yourself?

The full Flask bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.

Take the Flask quiz