4

I have no idea how to fix this problem that I get from my Python code when I am using Flask:

@app.route('/addEvent/', methods=['POST'])
def addEvent():

@app.route('/deleteEvent/', methods=['POST'])
def addEvent():

Error message:

AssertionError: View function mapping is overwriting an existing endpoint function: addEvent
21:50:57 web.1  | Traceback (most recent call last):

I tried understanding this page: http://flask.pocoo.org/docs/0.10/patterns/viewdecorators/

Also this post AssertionError: View function mapping is overwriting an existing endpoint function: main

But I don't understand. Could someone please tell me how to fix this for my code?

Community
  • 1
  • 1

1 Answers1

9

Rename the second function; it too is called addEvent; I suggest deleteEvent instead:

@app.route('/deleteEvent/', methods=['POST'])
def deleteEvent():

The endpoint name is normally taken from the function you decorated with @app.route(); you can also explicitly give your endpoint a different name by telling the decorator what name you'd want to use instead:

@app.route('/deleteEvent/', methods=['POST'], endpoint='deleteEvent')
def addEvent():

which would let you stick to using the same name for the function. In this specific case, that's not a good idea, because one function replaced the other and the only reference left to the first is in the Flask URL map.

Also see the Flask.route() documentation:

endpoint – the endpoint for the registered URL rule. Flask itself assumes the name of the view function as endpoint.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343