What is an 'endpoint' in Flask?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Flask, an endpoint is the internal name Flask uses for a route target. It is not the URL itself, although the two are often discussed together. Understanding the difference matters because URL matching is done by path, while URL generation with url_for is done by endpoint name.
Route, View Function, and Endpoint
A Flask route has three related pieces:
- the URL rule, such as
/users/<id> - the view function that handles the request
- the endpoint name that identifies that view inside Flask
Simple example:
Here:
- URL rule is
/hello - view function is
hello - endpoint is also
hello
By default, Flask uses the function name as the endpoint name.
Why Endpoints Matter
Endpoints are most visible when you call url_for.
url_for("hello") does not look up the string "/hello" directly. It looks up the endpoint named hello, then generates the corresponding URL.
That indirection is important because it decouples your application code from hardcoded URL strings.
Dynamic Routes Still Use One Endpoint Name
A dynamic URL can still map to a single endpoint.
The endpoint is user_detail, and url_for fills in the variable part of the route using the keyword arguments.
Custom Endpoint Names
You can override the default endpoint name when registering a route.
Now the route is reached at /status, but the endpoint name is healthcheck, not status.
That means:
This is useful when you want the internal route name to stay stable even if the function name changes.
Blueprints Prefix Endpoints
Blueprints help organize larger Flask apps, and they change endpoint naming by prefixing the blueprint name.
The endpoint becomes admin.dashboard, not just dashboard. This avoids collisions between similarly named views in different parts of the app.
Inspect Registered Endpoints
Flask keeps an internal mapping of endpoint names to view functions.
This can be useful when debugging duplicate endpoint registration or understanding how blueprints expanded route names.
Common Source of Confusion
People often use "endpoint" to mean the public API path, especially in REST conversations. In Flask-specific terms, though, the endpoint is the internal routing name.
So these two uses are related but not identical:
- "The API endpoint is
/users/42" is common API language. - "The Flask endpoint is
user_detail" is framework-specific routing language.
Both are understandable in context, but only the second matches Flask internals exactly.
Why url_for Is Better Than Hardcoding Paths
If you hardcode "/hello" everywhere, changing the route later means manual edits across templates and view code.
Using endpoints keeps URL generation centralized:
If the URL rule changes later, code using url_for("login") can keep working.
Common Pitfalls
One common mistake is assuming the endpoint name is always the same as the URL path. In Flask, it is usually the function name unless overridden.
Another mistake is forgetting blueprint prefixes and calling url_for("dashboard") when the real endpoint is admin.dashboard.
Developers also create duplicate endpoint names accidentally when reusing function names across modules without blueprints or explicit endpoint control.
Finally, hardcoding URLs instead of using url_for makes refactoring routes much harder than it needs to be.
Summary
- In Flask, an endpoint is the internal name associated with a route target.
- By default, the endpoint name is the view function name.
- '
url_forgenerates URLs by endpoint name, not by raw path string.' - Blueprints prefix endpoint names to avoid collisions.
- Understanding endpoints makes routing, refactoring, and URL generation much clearer.

