Does anyone know why I can't overwrite an existing endpoint function if i have two url rules like this
app.add_url_rule('/',
view_func=Main.as_view('main'),
methods=["GET"])
app.add_url_rule('/<page>/',
view_func=Main.as_view('main'),
methods=["GET"])
Traceback:
Traceback (most recent call last):
File "demo.py", line 20, in <module> methods=["GET"])
File ".../python2.6/site-packages/flask/app.py",
line 62, in wrapper_func return f(self, *args, **kwargs)
File ".../python2.6/site-packages/flask/app.py",
line 984, in add_url_rule 'existing endpoint function: %s' % endpoint)
AssertionError: View function mapping is overwriting an existing endpoint
function: main
There is a fix for Flask issue #570 introduced recenty (flask 0.10) that causes this exception to be raised.
See https://github.com/mitsuhiko/flask/issues/796
So if you go to flask/app.py and comment out the 4 lines 948..951, this may help until the issue is resovled fully in a new version.
The diff of that change is here: http://github.com/mitsuhiko/flask/commit/661ee54bc2bc1ea0763ac9c226f8e14bb0beb5b1
I would just like to add to this a more 'template' type solution.
Flask requires you to associate a single 'view function' with an 'endpoint'. You are calling
Main.as_view('main')
twice which creates two different functions (exactly the same functionality but different in memory signature). Short story, you should simply doThis same issue happen to me but with a different usage. When I tried to wrap an API function with 2 decorators:
I got this same exception because I tried to wrap more than one function with those two decorators:
Specifically, it is caused by trying to register a few functions with the name wrapper:
Changing the name of the function solved it for me (wrapper.func_name = func.func_name):
Then, decorating more than one endpoint worked.
Your view names need to be unique even if they are pointing to the same view method.
If you think you have unique endpoint names and still this error is given then probably you are facing issue. Same was the case with me.
This issue is with flask 0.10 in case you have same version then do following to get rid of this: