AssertionError: View function mapping is overwriting an existing endpoint function: insertCase
is View an Function Mapping existing Endpoint
2023-09-27 14:25:18 时间
首先,理解这个错误是什么意思,以及出现的原因:
使用Flask定义URL的时候,如果出现"AssertionError: View function mapping is overwriting an existing endpoint function"这个异常信息,就说明定义了多个同名的视图函数,只需要改成不同的函数名即可。
这是为什么呢?
原来flask中url跟视图函数并不是直接对应的,而是有一个中间者-endpoint。
三者之间的关系是这样的:
```
url---->endpoint---->view_function
```
它们是一对一的关系,在注册add_url_rule的时候,如果不指定endpoint,那么endpoint就会默认为函数名字,如果同一个endpoint于多个url注册的话,就会发生冲突,从而抛出异常。
我出错误的原因:
在项目的初始文件 init中
我导入了views模块,这相当于会执行views中的代码(变量定义,视图函数等)
然后我在views模块想要调试的时候,就相当于再次定义一样的变量,视图函数,所以就会出现上面的错误,即定义了多个同名的视图函数
解决办法:
这里把init中这句代码注释掉就可以了
再次单独运行views文件即可正常启动服务了
参考:
理解endpoint是什么:
Flask中'endpoint'(端点)的理解(译文,不错的)
相关文章
- Docker上传镜像报错:denied: requested access to the resource is denied
- Lodop“对象不支持SET__LICENSES属性或方法”SET__LICENSES is not a function”
- 报错 RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation
- npm is known not to run on Node.js v8.15.0
- Access restriction: The type Resource is not accessible due to restriction on required library
- 测试webservice的时候,如果出现这个错误:"The test form is only available for requests from the local machine"
- sqlalchemy.exc.InvalidRequestError: Table 'run_result' is already defined for this MetaData instance
- Gunicorn启动时 nginx 400 request line is too large (4360 4094)
- dll is in timestamps but is not known in guidmapper… 错误
- Docker - 解决运行容器报 WARNING: IPv4 forwarding is disabled. Networking will not work. 的问题
- 成功解决:_vm.Login is not a function
- 自然语言处理NLP星空智能对话机器人系列:论文解读 How Good is Your Tokenizer? (你的词元分析器有多好?多语言模型的单语性能研究)
- Android:What is ART?
- Bringing up interface eth0: Determining if ip address 10.109.67.81 is already in use for device eth0...
- There is an overlap in the region chain修复