Flask
web development
routing
Python
API

List all routes in a Flask app (app.url_map and flask routes)

Codemia Knowledge Hub ·

Flask stores every registered URL rule in app.url_map. Iterate over app.url_map.iter_rules() to print each route's path, endpoint and methods, or run flask --app app routes to get the table without writing code. A route listing helps with debugging, documentation, permission reviews and checking that blueprints registered as expected.

Iterate app.url_map.iter_rules()

python
1from flask import Flask, jsonify
2
3app = Flask(__name__)
4
5@app.get("/")
6def home():
7    return "ok"
8
9@app.post("/users")
10def create_user():
11    return jsonify(created=True), 201
12
13@app.get("/users/<int:user_id>")
14def get_user(user_id):
15    return jsonify(user_id=user_id)
16
17for rule in app.url_map.iter_rules():
18    methods = ", ".join(sorted(rule.methods - {"HEAD", "OPTIONS"}))
19    print(f"{rule.endpoint:20} {methods:10} {rule.rule}")

Each rule object carries useful metadata:

  • rule.rule is the URL pattern.
  • rule.endpoint is the internal endpoint name, usually the view function name.
  • rule.methods is the set of HTTP methods allowed for that route.

Example output, including the static route

The code above prints something like:

text
1static               GET        /static/<path:filename>
2home                 GET        /
3create_user          POST       /users
4get_user             GET        /users/<int:user_id>

Flask adds the static route automatically unless static serving is disabled, which is why an unexpected route often appears in the output.

The flask routes CLI command

bash
flask --app app routes

This is often the fastest option during local development. It prints a table of routes after Flask imports the application. For app factories, pass the correct import path so Flask can create the app first.

Filtering routes for documentation

The full table may include static files, internal endpoints or methods you do not care about. Filter the rules:

python
1for rule in app.url_map.iter_rules():
2    if rule.endpoint == "static":
3        continue
4
5    methods = sorted(rule.methods - {"HEAD", "OPTIONS"})
6    if "GET" in methods:
7        print(rule.rule)

This is useful for generating internal docs or checking only API endpoints.

Blueprint routes

Blueprint routes end up in the main app's URL map after registration. Their endpoints are usually prefixed: a route in a blueprint named admin may appear as admin.dashboard, which makes it easy to group routes by module.

Surprises in the route list

  • HEAD and OPTIONS appear even when you only declared GET, because Flask adds some methods automatically. Filter them out for a cleaner list.
  • If flask routes shows nothing useful, make sure the --app argument points to the correct module or factory.
  • A route listing says nothing about access control. A route may still require authentication, role checks or other guards inside the view.
  • Endpoint names are not URLs. rule.endpoint is the identifier used by url_for, while rule.rule is the URL pattern.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design