All questions
Showing of 60How do you create a basic Flask application?
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:
Last attempt -
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.
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 ↓
What is the significance of __name__ in Flask(__name__)?
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:
Last attempt -
__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.
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 ↓
How do you handle different HTTP methods in Flask routes?
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:
Last attempt -
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.
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 ↓
What are URL variables and how do you use them?
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:
Last attempt -
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>:
stringis the default and accepts any text without a slash.intaccepts positive integers.floataccepts positive floating point values.pathis likestringbut also accepts slashes.uuidaccepts 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.
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 ↓
What is URL building and how do you use url_for()?
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:
Last attempt -
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.
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 ↓
How do you handle query parameters in Flask?
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:
Last attempt -
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=abcgives1.getlist('category')returns every value, so?category=a&category=bgives 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.
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 ↓
How do you access request data in Flask?
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:
Last attempt -
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.formholds fields from a form body.form['username']raises aKeyErrorwhen the field is missing, and Flask turns that into400 Bad Request.form.get()returns a default instead.request.filesholds uploads. It stays empty unless the form was sent asmultipart/form-data.request.headersandrequest.cookieswork like dictionaries, soget()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.
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 ↓
What's the difference between request.form, request.args, and request.get_json() ?
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:
Last attempt -
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.
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 ↓
What are Flask's built-in response helpers?
How do you render templates in Flask?
How do you pass data to templates?
How do you handle forms in Flask?
How do you manage sessions in Flask?
How do you handle errors in Flask?
What are Flask environment variables and how do you use them?
What is Flask, and why is it called a microframework?
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:
Last attempt -
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.
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 ↓
What is message flashing in Flask?
How do you create custom response objects?
What are the key features of Jinja2 templating?
What are Jinja2 filters and how do you create custom ones?
How do you handle template inheritance?
What is WSGI and how does Flask relate to it?
Explain the Flask application context and request context.
How do you create URL rules dynamically?
How do you handle file uploads in Flask?
What is Flask-WTF and how does it help with forms?
How do you implement CSRF protection in Flask?
How do you perform custom form validation?
How do you integrate databases with Flask?
What are database migrations and how do you handle them?
How do you perform database queries in Flask-SQLAlchemy?
How do you define relationships between models?
What are the different session storage options in Flask?
How do you implement user authentication in Flask?
How do you implement custom exceptions?
How do you implement logging in Flask?
What are common security vulnerabilities in Flask applications?
How do you secure Flask applications?
How do you handle password security?
What are Flask Blueprints and why use them?
How do you structure a large Flask application?
What is the Application Factory pattern?
How do you create RESTful APIs with Flask?
How do you handle JSON serialization for complex objects?
How do you implement API versioning in Flask?
How do you test Flask applications?
How do you test API endpoints?
How do you mock dependencies in Flask tests?
How do you configure Flask applications for different environments?
How do you deploy Flask applications?
How do you implement rate limiting in Flask applications?
How do you handle database transactions in Flask?
How do you implement caching in Flask?
How do you handle API authentication and authorization?
How do you implement background tasks in Flask?
How do you implement WebSocket support in Flask?
How do you handle database connection pooling?
How do you implement custom middleware in Flask?
Does Flask support async views, and what are their limits?
Walk me through the lifecycle of a Flask request.
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
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.
Flask cheatsheet
- How Flask runs a request01
- Routes, requests & responses02
- Templates & forms03
- Sessions, login & tokens04
- SQLAlchemy & migrations05
- App structure & config06
- REST APIs, errors & tests07
- Security & deployment08
- Caching, tasks & WebSockets09
- The model10
- + 4 more inside
This picture is part of Pro. The first chapter is free to play; the other 26 pictures come with Pro.
Get Pro · $10/mo Already Pro? Sign in51 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.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.