Flask interview questions for freshers test whether you can build a small web app or API in Python. Expect questions on routes, URL variables, request data, templates, JSON responses and the difference between Flask and Django. This page has 25 questions with short answers, and the code was run with Flask 3 to confirm the output.
Code samples assume from flask import Flask and an app created with app = Flask(__name__). Imports are shown where a sample needs more.
How to answer Flask interview questions
Answer with what it is, a tiny code line and why it matters. "A route maps a URL to a Python function. @app.route('/users/<int:user_id>') passes the id as an integer, and a non-number gives a 404."
Pro tip: Flask questions often turn into "write the route". Practise a GET route with a URL variable and a POST route that reads JSON until you can type both without looking.
Flask basics questions
Q1. What is Flask?
30-second answer: Flask is a lightweight web framework for Python. It gives you routing, request and response handling, and templates through Jinja, and leaves choices such as the database and login system to you. It is called a micro-framework because the core is small, not because apps must be small.
Flask is built on Werkzeug (the WSGI toolkit that handles HTTP) and Jinja (the template engine).
Q2. Write a minimal Flask app.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, Flask!"
if __name__ == "__main__":
app.run(debug=True)
30-second answer: Create a Flask object, map a URL to a function with @app.route, and return a response. A GET request to / returns Hello, Flask! with status 200.
Q3. How do you run a Flask app?
30-second answer: From the project folder, run flask --app app run, where app is the file name without .py. Add --debug to turn on the reloader and the debugger. You can also run python app.py if the file calls app.run().
Never use debug mode in production. The debugger lets anyone who reaches the error page run code on the server.
Q4. What does __name__ do in Flask(__name__)?
30-second answer: It tells Flask where the app lives, so it can find the templates and static folders next to the module. When the file is run directly, __name__ is "__main__"; when it is imported, it is the module name.
Q5. What is WSGI?
30-second answer: WSGI (Web Server Gateway Interface) is the standard way Python web apps talk to web servers. A Flask app is a WSGI app. In production you run it with a WSGI server such as Gunicorn or Waitress, often behind Nginx, instead of the built-in development server.
Q6. What is the difference between Flask and Django?
| Point | Flask | Django |
|---|---|---|
| Type | Micro-framework | Full-stack framework |
| Built in | Routing, templates, request handling | ORM, admin panel, auth, forms, migrations |
| Database | Your choice, often via an extension | Django ORM built in |
| Structure | You decide | Fixed project and app layout |
| Learning curve | Small to start | More to learn at first |
| Good for | Small APIs, services, prototypes | Large sites with many standard features |
30-second answer: Flask gives you less and lets you choose the rest. Django gives you most things built in and expects you to follow its structure. Read Django vs Flask for a full comparison, and the Django interview questions if the job mentions both.
Routing questions
Q7. What is a route in Flask?
30-second answer: A route maps a URL path to a Python function, called a view function. The @app.route() decorator registers it. When a request matches the path, Flask calls the function and turns its return value into a response.
Q8. What are variable rules in a route?
30-second answer: Parts of the URL inside angle brackets are passed to the function as arguments. A converter sets the type.
@app.route("/users/<int:user_id>")
def show_user(user_id):
return f"User {user_id}"
/users/7 returns User 7. /users/abc returns 404, because abc does not match int. Built-in converters are string (the default), int, float, path and uuid.
Q9. How do you allow POST requests on a route?
30-second answer: Pass methods to the decorator, or use the shortcut decorators added in Flask 2.0.
@app.route("/login", methods=["GET", "POST"])
def login():
...
@app.post("/api/students")
def add_student():
...
A route accepts only GET (and HEAD and OPTIONS) by default. Sending POST to a GET-only route returns 405 Method Not Allowed. See GET vs POST for when to use each.
Q10. What is url_for, and why use it?
30-second answer: url_for builds a URL from a view function's name, so you do not hard-code paths. If the route changes, every link still works.
from flask import url_for
with app.test_request_context():
print(url_for("show_user", user_id=5))
print(url_for("search", q="sql"))
Output:
/users/5
/search?q=sql
Unknown arguments, such as q here, are added as query parameters. In templates, write {{ url_for('static', filename='style.css') }} for static files.
Q11. How do you redirect a user?
30-second answer: Return redirect() with the target URL, usually built with url_for.
from flask import redirect, url_for
@app.route("/old-home")
def old_home():
return redirect(url_for("home"))
The default status is 302. Pass code=301 for a permanent redirect.
Request handling questions
Q12. How do you read query parameters?
30-second answer: Use request.args, which works like a dictionary. get() returns a default if the key is missing, and type= converts the value.
from flask import request
@app.route("/search")
def search():
q = request.args.get("q", "")
page = request.args.get("page", 1, type=int)
return f"q={q}, page={page}"
/search?q=flask&page=2 returns q=flask, page=2. /search returns q=, page=1.
Q13. How do you read form data and JSON?
| Data | How to read it |
|---|---|
Query string ?q=x |
request.args |
| HTML form fields | request.form |
| JSON body | request.get_json() or request.json |
| Uploaded files | request.files |
| Headers | request.headers |
| Cookies | request.cookies |
30-second answer: Pick the attribute that matches where the data comes from. request.form["email"] raises an error that returns 400 if the field is missing, so use request.form.get("email") when it is optional.
Q14. What is the request object, and how can it be global?
30-second answer: request holds the current HTTP request: method, URL, headers and data. It looks global, but Flask uses context locals, so each request sees its own data even when many requests run at the same time. It only works inside a request, such as in a view function.
Q15. What can a view function return?
30-second answer: A string (sent as HTML), a dictionary or list (sent as JSON), a Response object, or a tuple with a status code and optional headers.
return "Created", 201
return {"error": "name is required"}, 400
return "Moved", 302, {"Location": "/new"}
Template questions
Q16. How do templates work in Flask?
30-second answer: Flask uses Jinja templates stored in a templates folder. render_template fills in the values and returns HTML.
<!-- templates/hello.html -->
<h1>Hello, {{ name }}!</h1>
<ul>
{% for s in skills %} <li>{{ s }}</li>
{% endfor %}</ul>
from flask import render_template
@app.route("/hello/<name>")
def hello(name):
return render_template("hello.html", name=name, skills=["Python", "SQL"])
Output for /hello/Asha:
<h1>Hello, Asha!</h1>
<ul>
<li>Python</li>
<li>SQL</li>
</ul>
Q17. What is the difference between {{ }} and {% %} in Jinja?
30-second answer: {{ }} prints a value. {% %} runs logic, such as if, for, block and extends. {# #} is a comment.
Q18. What is template inheritance?
30-second answer: A base template defines the common layout with named blocks. Child templates extend it and fill the blocks, so the header and footer are written once.
<!-- base.html -->
<title>{% block title %}My Site{% endblock %}</title>
<main>{% block content %}{% endblock %}</main>
<!-- home.html -->
{% extends "base.html" %}
{% block content %}<p>Welcome</p>{% endblock %}
Q19. Does Jinja protect against XSS?
30-second answer: Yes, for templates ending in .html, Flask turns on auto-escaping. A value like <script> is shown as text, not run. The |safe filter turns escaping off, so use it only for HTML you trust.
Simple REST API questions
Q20. Write a small REST API with GET and POST.
from flask import Flask, request, jsonify, abort
app = Flask(__name__)
students = [{"id": 1, "name": "Asha"}, {"id": 2, "name": "Ravi"}]
@app.get("/api/students")
def list_students():
return jsonify(students)
@app.get("/api/students/<int:sid>")
def get_student(sid):
for s in students:
if s["id"] == sid:
return s
abort(404)
@app.post("/api/students")
def add_student():
data = request.get_json()
if not data or "name" not in data:
return {"error": "name is required"}, 400
new = {"id": len(students) + 1, "name": data["name"]}
students.append(new)
return new, 201
@app.errorhandler(404)
def not_found(e):
return {"error": "not found"}, 404
Results from Flask's test client:
| Request | Status | Body |
|---|---|---|
| GET /api/students | 200 | [{"id":1,"name":"Asha"},{"id":2,"name":"Ravi"}] |
| GET /api/students/2 | 200 | {"id":2,"name":"Ravi"} |
| GET /api/students/9 | 404 | {"error":"not found"} |
POST {"name": "Meena"} |
201 | {"id":3,"name":"Meena"} |
POST {} |
400 | {"error":"name is required"} |
30-second answer: GET routes read data, POST creates it and returns 201, and bad input gets a 4xx with a clear message. A real app stores data in a database, not a list. The REST API basics page explains the ideas behind these routes.
Q21. What is the difference between jsonify and returning a dictionary?
30-second answer: Both send JSON with the application/json content type. Since Flask 1.1 you can return a dictionary directly, and since Flask 2.2 a list too. jsonify is still useful in older code and when you want to build the response object first.
Q22. How do you handle errors in Flask?
30-second answer: Call abort(404) (or another code) to stop and return an error. Register @app.errorhandler(404) to control what the error response looks like, such as JSON for an API instead of the default HTML page.
Sessions, blueprints and structure questions
Q23. How do sessions work in Flask?
30-second answer: session is a dictionary stored in a signed cookie in the browser. Flask signs it with app.secret_key, so users can read but not change it without the key. Do not store passwords or sensitive data in it.
from flask import session
app.secret_key = "change-this-in-production"
@app.route("/set")
def set_user():
session["user"] = "asha"
return "saved"
Load the real secret key from an environment variable, never from code you commit.
Q24. What are blueprints?
30-second answer: A blueprint groups related routes, templates and static files so a larger app can be split into parts, such as auth and api. You register each blueprint on the app, often with a URL prefix.
from flask import Blueprint
api = Blueprint("api", __name__, url_prefix="/api")
@api.get("/health")
def health():
return {"status": "ok"}
app.register_blueprint(api) # route is now /api/health
Q25. Which Flask extensions are commonly used?
| Extension | Used for |
|---|---|
| Flask-SQLAlchemy | Database models with SQLAlchemy |
| Flask-Migrate | Database migrations |
| Flask-Login | User login sessions |
| Flask-WTF | Forms and CSRF protection |
| Flask-CORS | Allowing calls from other domains |
30-second answer: Flask stays small and you add what you need. Name the ones you used in your project and what each did.
Quick revision table
| Topic | One line to remember |
|---|---|
| Route | URL mapped to a function with @app.route |
| Variable rule | <int:id> passes a typed value |
request.args |
Query string values |
request.get_json() |
JSON body |
render_template |
Fills a Jinja template |
url_for |
Builds URLs from function names |
abort / errorhandler |
Raise and shape errors |
session |
Signed cookie, needs secret_key |
| Blueprint | Groups routes into modules |
How to prepare in one week
| Day | Task |
|---|---|
| 1 | Minimal app, routes and variable rules |
| 2 | Query strings, forms and JSON |
| 3 | Templates and inheritance |
| 4 | CRUD API for one resource |
| 5 | Add SQLite and error handlers |
| 6 | Blueprints and a clean folder layout |
| 7 | Revise and do a mock interview |
Flask rounds also test Python itself, so revise the Python interview questions before the technical round.

