AssertionError: View function mapping is overwriting an existing endpoint function

后端 未结 1 983
借酒劲吻你
借酒劲吻你 2021-01-28 00:21

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         


        
相关标签:
1条回答
  • 2021-01-28 01:18

    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.

    0 讨论(0)
提交回复
热议问题