python - 断言错误 : View function mapping is overwriti

我不知道如何解决我在使用 Flask 时从 Python 代码中遇到的这个问题:

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

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

错误信息:

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

我试着理解这个页面:http://flask.pocoo.org/docs/0.10/patterns/viewdecorators/

还有这篇文章AssertionError: View function mapping is overwriting an existing endpoint function: main

但是我不明白。有人可以告诉我如何为我的代码解决这个问题吗?

最佳答案

重命名第二个函数;它也被称为 addEvent;我建议改为使用 deleteEvent:

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

端点 名称通常取自您用@app.route() 修饰的函数;您还可以通过告诉装饰器您想要使用什么名称来显式地为您的端点指定一个不同的名称:

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

这会让您坚持为函数使用相同的名称。在这种特定情况下,这不是一个好主意,因为一个函数替换了另一个函数,而第一个函数的唯一引用是在 Flask URL 映射中。

另见 Flask.route() documentation :

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

关于python - 断言错误 : View function mapping is overwriting an existing endpoint function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28819876/

相关文章:

git - 如何在不推送我的情况下从 GitHub pull 更改?

git - 将远程分支重置为之前的提交

python - 使用 np.arrays python 对列表进行排序

javafx - 在 Eclipse Luna 中使用 JavaFX (JDK 1.8.0_40)

angularjs - 嵌套的 ng-repeat 中的 Angular ng-bind-html

objective-c - 如何在 Xcode 6 中禁用 ARC

function - 使用 VHDL 中的函数进行综合

php - 从 html 下载图像并保持文件夹结构

asp.net-mvc - Razor Html.Raw 无法呈现 ViewModel 数据

java - spring boot 启动rest服务失败