LearnThatStack Ace your next interview
Backend Development

Flask.

Start free Change topic Change
Practice · Questions

All questions

Showing of 60
Beginner 21
01

How do you create a basic Flask application?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Create an instance of the Flask class, then map URLs to view functions with the @app.route() decorator.

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

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

Flask(__name__) creates the application instance, the object a web server calls for each request. The @app.route('/') decorator binds / to hello_world, and the returned string becomes the response body.

app.run(debug=True) starts the development server when you run the file directly. From the terminal, flask --app hello run --debug does the same, where hello is the module name. Use the development server and its debugger only on your own machine, never in production.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What is the significance of __name__ in Flask(__name__)?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

__name__ gives Flask the import name of the module or package that holds the app. Flask uses it to find the app's root path, so it knows where to look for the templates and static folders.

The import name also helps tools around the app. Extensions can use it for debugging information. Flask-SQLAlchemy, for example, uses it to show which code in your app ran a query.

The value depends on how the file runs. When you run it directly, __name__ is '__main__'. When it is imported, __name__ holds the real module name, such as myapp.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

How do you handle different HTTP methods in Flask routes?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Pass a methods list to the route decorator, then branch on request.method inside the view. Without that list, a route answers only GET.

@app.route('/api/users', methods=['GET', 'POST'])
def handle_users():
    if request.method == 'POST':
        return create_user()
    return get_users()

@app.route('/api/users/<int:user_id>', methods=['PUT', 'DELETE'])
def handle_user(user_id):
    if request.method == 'PUT':
        return update_user(user_id)
    elif request.method == 'DELETE':
        return delete_user(user_id)

Flask adds HEAD for you whenever GET is allowed, and it answers OPTIONS requests on its own. A request with any other method gets 405 Method Not Allowed, and the view never runs.

One view for several methods suits code that shares setup. Separate views are often easier to read, and Flask has shortcut decorators such as @app.get() and @app.post() for them. For a whole resource, MethodView maps each HTTP method to a class method with the same name, such as get or delete.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What are URL variables and how do you use them?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

URL variables are parts of a route marked with angle brackets, such as <username>. Flask captures that part of the URL and passes it to the view as a keyword argument.

@app.route('/user/<username>')
def show_user(username):
    return f'User: {username}'

@app.route('/post/<int:post_id>')
def show_post(post_id):
    return f'Post ID: {post_id}'

@app.route('/path/<path:subpath>')
def show_subpath(subpath):
    return f'Subpath: {subpath}'

A converter sets the type, as in <int:post_id>:

  • string is the default and accepts any text without a slash.
  • int accepts positive integers.
  • float accepts positive floating point values.
  • path is like string but also accepts slashes.
  • uuid accepts UUID strings.

A value that does not fit its converter matches no route, so /post/abc returns 404 Not Found and never reaches show_post.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

What is URL building and how do you use url_for()?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

URL building means generating a URL from an endpoint name instead of typing the path by hand. url_for() takes the endpoint, usually the view function's name, plus a keyword argument for each URL variable.

from flask import url_for

@app.route('/user/<username>')
def user_profile(username):
    return f'Profile for {username}'

@app.route('/')
def index():
    # Generate URL for user_profile endpoint
    profile_url = url_for('user_profile', username='john')
    return f'<a href="{profile_url}">John\'s Profile</a>'

Here url_for('user_profile', username='john') returns /user/john. Arguments that match no URL variable become query parameters. This reverse lookup has three benefits:

  • Changing a route updates every link that uses its endpoint.
  • Special characters are escaped for you.
  • The paths are absolute, and they stay correct when the app is mounted under a prefix.
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

How do you handle query parameters in Flask?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Read them from request.args, which holds the parsed query string as a MultiDict. A MultiDict can keep several values for one key.

from flask import request

@app.route('/search')
def search():
    query = request.args.get('q', '')
    page = request.args.get('page', 1, type=int)
    category = request.args.getlist('category')  # Multiple values
    
    return f'Query: {query}, Page: {page}, Categories: {category}'
  • get('q', '') returns the default when the key is missing.
  • get('page', 1, type=int) converts the value and falls back to the default when the conversion fails, so ?page=abc gives 1.
  • getlist('category') returns every value, so ?category=a&category=b gives both, and a missing key gives an empty list.

Indexing with request.args['q'] raises a KeyError for a missing key, and Flask turns that into 400 Bad Request. Prefer get(), because users can edit a URL by hand. Values arrive as strings until you convert them.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

How do you access request data in Flask?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Import the request object and read the attribute for the part of the request you need. request looks like a global, but it is a context-local proxy, so each worker sees only the request it is handling.

from flask import request

@app.route('/form', methods=['POST'])
def handle_form():
    # Form data
    username = request.form['username']
    email = request.form.get('email', '')
    
    # Files
    if 'file' in request.files:
        file = request.files['file']
    
    # Headers
    auth_header = request.headers.get('Authorization')
    
    # Cookies
    session_id = request.cookies.get('session_id')
    
    return 'Data processed'
  • request.form holds fields from a form body. form['username'] raises a KeyError when the field is missing, and Flask turns that into 400 Bad Request. form.get() returns a default instead.
  • request.files holds uploads. It stays empty unless the form was sent as multipart/form-data.
  • request.headers and request.cookies work like dictionaries, so get() is the safe way to read them.

Other parts sit beside these. request.args holds the query string, request.get_json() parses a JSON body, and request.method gives the HTTP method.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

What's the difference between request.form, request.args, and request.get_json()?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

They read three different parts of a request. request.args is the URL query string, request.form is a form-encoded body, and request.get_json() parses a JSON body.

request.args request.form request.get_json()
Source Query string after ? Request body Request body
Content type Any application/x-www-form-urlencoded or multipart/form-data application/json
Returns MultiDict of strings MultiDict of strings Parsed dict or list
When the data is absent get() returns None get() returns None 415 error, or None with silent=True
# URL: /api?page=1
# Body: {"name": "John"}

@app.route('/api', methods=['POST'])
def api():
    page = request.args.get('page')        # "1"
    name = request.get_json()['name']      # "John"
    username = request.form.get('username') # None, because the body is JSON

A request has only one body, so form and get_json() never both get data from the same request. That is why username is None above. When either source is fine, request.values combines args and form. Use args for filters and paging, form for HTML form posts, and get_json() for API clients.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

09

What are Flask's built-in response helpers?

Part of Pro
10

How do you render templates in Flask?

Part of Pro
11

How do you pass data to templates?

Part of Pro
12

How do you handle forms in Flask?

Part of Pro Visual
13

How do you manage sessions in Flask?

Part of Pro Visual
14

How do you handle errors in Flask?

Part of Pro
15

What are Flask environment variables and how do you use them?

Part of Pro
16

What is Flask, and why is it called a microframework?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Flask is a lightweight Python web framework for building web apps and APIs. Its core handles routing, requests and templates, and leaves the other choices to you.

It is called a microframework because its core stays small but extensible. Apps built with it do not have to be small. Flask has no database layer, form library or user system. You add those through extensions such as Flask-SQLAlchemy and Flask-Login, or with any library you prefer.

Flask is built on two libraries:

  • Werkzeug handles the low-level request and response work, the routing and the development server.
  • Jinja renders the templates.

The trade-off is that you choose and wire up the database layer, forms and user system yourself.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

17

What is message flashing in Flask?

Part of Pro
18

How do you create custom response objects?

Part of Pro
19

What are the key features of Jinja2 templating?

Part of Pro
20

What are Jinja2 filters and how do you create custom ones?

Part of Pro
21

How do you handle template inheritance?

Part of Pro
Intermediate 32
22

What is WSGI and how does Flask relate to it?

Part of Pro
23

Explain the Flask application context and request context.

Part of Pro Visual
24

How do you create URL rules dynamically?

Part of Pro Visual
25

How do you handle file uploads in Flask?

Part of Pro
26

What is Flask-WTF and how does it help with forms?

Part of Pro
27

How do you implement CSRF protection in Flask?

Part of Pro Visual
28

How do you perform custom form validation?

Part of Pro Visual
29

How do you integrate databases with Flask?

Part of Pro
30

What are database migrations and how do you handle them?

Part of Pro
31

How do you perform database queries in Flask-SQLAlchemy?

Part of Pro
32

How do you define relationships between models?

Part of Pro
33

What are the different session storage options in Flask?

Part of Pro
34

How do you implement user authentication in Flask?

Part of Pro
35

How do you implement custom exceptions?

Part of Pro
36

How do you implement logging in Flask?

Part of Pro
37

What are common security vulnerabilities in Flask applications?

Part of Pro
38

How do you secure Flask applications?

Part of Pro
39

How do you handle password security?

Part of Pro Visual
40

What are Flask Blueprints and why use them?

Part of Pro
41

How do you structure a large Flask application?

Part of Pro
42

What is the Application Factory pattern?

Part of Pro
43

How do you create RESTful APIs with Flask?

Part of Pro
44

How do you handle JSON serialization for complex objects?

Part of Pro
45

How do you implement API versioning in Flask?

Part of Pro
46

How do you test Flask applications?

Part of Pro
47

How do you test API endpoints?

Part of Pro
48

How do you mock dependencies in Flask tests?

Part of Pro Visual
49

How do you configure Flask applications for different environments?

Part of Pro
50

How do you deploy Flask applications?

Part of Pro
51

How do you implement rate limiting in Flask applications?

Part of Pro Visual
52

How do you handle database transactions in Flask?

Part of Pro Visual
53

How do you implement caching in Flask?

Part of Pro
Expert 7
54

How do you handle API authentication and authorization?

Part of Pro
55

How do you implement background tasks in Flask?

Part of Pro Visual
56

How do you implement WebSocket support in Flask?

Part of Pro Visual
57

How do you handle database connection pooling?

Part of Pro
58

How do you implement custom middleware in Flask?

Part of Pro
59

Does Flask support async views, and what are their limits?

Part of Pro Visual
60

Walk me through the lifecycle of a Flask request.

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for Flask? Send them this set.
Quick recap

Flask in pictures.

A quick recap of Flask in 30 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.

Pro The first chapter is free to play. The other 26 pictures come with Pro.

Get Pro · $10/mo
Pro · $10/mo

51 of 60 Flask answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git