AssertionError:视图函数映射正在覆盖现有的终结点函数 [英] AssertionError: View function mapping is overwriting an existing endpoint function

查看:62
本文介绍了AssertionError:视图函数映射正在覆盖现有的终结点函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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():

错误消息:

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:视图函数映射是覆盖现有的端点函数:main

但是我不明白.有人可以告诉我如何为我的代码修复此问题吗?

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

推荐答案

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

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

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

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

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():

,让您坚持使用相同的功能名称.在这种情况下,这不是一个好主意,因为一个函数替换了另一个函数,并且唯一留给第一个的引用是在Flask URL映射中.

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.

另请参见 Flask.route()文档:

Also see the Flask.route() documentation:

端点 –已注册的URL规则的端点. Flask本身将视图函数的名称假定为端点.

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

这篇关于AssertionError:视图函数映射正在覆盖现有的终结点函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆