shaare.it

AssertionError: View function mapping is overwriting an existing endpoint function

7 Dec 2025

1 min read

AssertionError: endpoint overwrite

$ flask run
Traceback (most recent call last):
  ...
AssertionError: View function mapping is overwriting an existing endpoint function: index

Why this happens

Two routes share the same endpoint name, typically due to duplicate function names or explicit endpoint arguments colliding. Blueprints merging can also cause duplicates.

Fix

  • Ensure unique function names or set distinct endpoint values.
  • For blueprints, prefix names or use url_prefix to avoid accidental overlaps.

Wrong code

from flask import Flask
app = Flask(__name__)

@app.route("/", endpoint="index")
def home():
    return "Home"

@app.route("/root", endpoint="index")
def root():
    return "Root"

Fixed code

from flask import Flask
app = Flask(__name__)

@app.route("/", endpoint="home")
def home():
    return "Home"

@app.route("/root", endpoint="root")
def root():
    return "Root"