【Flask】报错解决方法:AssertionError: View function mapping is overwriting an existing endpoint function: main.user
运行Flask时出现了一个错误, AssertionError: View function mapping is overwriting an existing endpoint function: main.user
直译就是视图方法中重写了一个存在的endpoint方法。那么问题来了,endpoint 是何方神圣?
查看了下源码,它的本质其实是请求url的一个规则,用来标记请求之后由哪个方法去具体执行。
@property
def endpoint(self):
"""The endpoint that matched the request. This in combination with
:attr:`view_args` can be used to reconstruct the same or a
modified URL. If an exception happened when matching, this will
be ``None``.
"""
if self.url_rule is not None:
return self.url_rule.endpoint
Flask官方文档中的解释:
endpoint(endpoint)
A decorator to register a function as an endpoint. Example:
@app.endpoint('example.endpoint')
def example():
return "example"
Parameters: endpoint – the name of the endpoint
以及其他函数中的用法,例如:add_url_rule()
add_url_rule(rule, endpoint=None,...) Parameters:
#...
endpoint – the endpoint for the registered URL rule. Flask itself assumes the name of the view function as endpoint
敲黑板划重点,Flask的默认endpoint其实就是视图模块中的各个具体方法名。
弄明白了endpoint,重新review下代码,发现确实是定义了相同方法名。
#...
@main.route('/user/<name>')
def user(name):
return render_template('user_simple.html',name=name)
#...
@main.route('/user/<username>')
def user(username):
user = User.query.filter_by(username=username).first_or_404()
return render_template('user.html',user=user)
找到问题根因,解决方法就so easy了,重命名其中一个方法名即可,问题搞定✿✿ヽ(°▽°)ノ✿
参考文档:http://flask.pocoo.org/docs/1.0/api/
【Flask】报错解决方法:AssertionError: View function mapping is overwriting an existing endpoint function: main.user的更多相关文章
- "AssertionError: View function mapping is overwriting an existing endpoint function"如何解决
使用Flask定义URL的时候,如果出现"AssertionError: View function mapping is overwriting an existing endpoint ...
- Flask之endpoint错误View function mapping is overwriting an existing endpoint function: ***
最近在学习Flask, 其中遇到了一个错误, 发现这个问题和Flask, 路由有关系, 所以就记了下来 错误代码: from flask import Flask, render_template, ...
- AssertionError: View function mapping is overwriting an existing endpoint function: insertCase
首先,理解这个错误是什么意思,以及出现的原因: 使用Flask定义URL的时候,如果出现"AssertionError: View function mapping is overwriti ...
- AssertionError: View function mapping is overwriting an existing endpoint function: admin.main
刚才给views.py文件添加了一个路由地址: @admin_view.route('/test', methods=["get", "post"]) @log ...
- MyEclipse Server view报错解决方法
MyEclipse Server view报错解决方法 方法/步骤 启动MyEclipse,弹出一个框,报错. ---------------------------------------- ...
- eclipse创建的maven项目,pom.xml文件报错解决方法
[错误一:]maven 编译级别过低 [解决办法:] 使用 maven-compiler-plugin 将 maven 编译级别改为 jdk1.6 以上: <!-- java编译插件 --> ...
- Loadrunner参数化逗号报错解决方法
Loadrunner参数化逗号报错解决方法 介绍Loadrunner参数化时,参数中包含有逗号时出错的解决方法. 在Loadrunner进行参数化时,参数中如果含有逗号,编辑保存后会报错: 此 ...
- Android Studio support 26.0.0-alpha1 Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法
AS下如何生成自定义的.jks签名文件, 以及如何生成数字签名 链接:http://www.cnblogs.com/smyhvae/p/4456420.html 链接:http://blog.csdn ...
- iOS url带中文下载时 报错解决方法
问题描述:下载文件时, 请求带中文的URL的资源时,比如:http://s237.sznews.com/pic/2010/11/23/e4fa5794926548ac953a8a525a23b6f2/ ...
随机推荐
- Spring boot的第一个demo
由于SpringBoot的问世使开发的门槛有降低了不少,就其这一点,早已使其名声大振,如雷贯耳.我之前是使用spring开发的,刚才使用了spring boot试验了一下,果然名不虚传,开发速度贼快. ...
- Mint-UI组件 MessageBox为prompt 添加判断条件
Mint-UI 的Message Box 是prompt类型时,可以添加正则判断或者function判断条件.具体可以查看Mint-UI源码. 添加正则判断条件: MessageBox({ $type ...
- <TCP/IP原理> (一)
1.协议和标准 2.标准化组织 3.Internet标准:RFC 4.Internet的管理机构 一.协议和标准 1.协议(Protocol) 一组控制数据通信的规则 三要素:语法(syntax).语 ...
- css:a:visited限制
:active 对于:active伪类可以在div上生效.没有限制 :visited使用限制 :visited只适用于带href的a标签.如果给a标签绑定了click事件,那跳转的url必须跟href ...
- 使用graphviz画图
安装: 要使用Graphviz,先要在系统上安装Graphviz. 在Ubuntu上安装可以使用命令: sudo apt-get install graphviz 在其他系统安装的方法可以查看Grap ...
- JAVA之锁-cas
CAS是什么? CAS是英文单词CompareAndSwap的缩写,中文意思是:比较并替换.CAS需要有3个操作数:内存地址V,旧的预期值A,即将要更新的目标值B. CAS指令执行时,当且仅当内存地址 ...
- windows的WSl安装mysql数据库以及操作数据库
1.更新 sudo apt-get update sudo apt-get upgrade 2.安装mysql sudo apt-get install mysql-server 3.开启服务 sud ...
- css 修改placeholder的颜色
input::-webkit-input-placeholder { color: #ff0000; } input::-moz-input-placeholder { color: #ff0000; ...
- Kafka(一)简介
1.Kafka简介 Kafka已经被很多公司广泛应用,一款实时流式消息组件.发送消息端称为Producer,接收端称为Consumer,Kafka集群有多个kafka实例组成,每个实例称为broker ...
- jenkins+supervisor实现django项目的自动部署(ubuntu)
没有安装supervisor的话首先安装supervisor, apt install upservisor 安装supervisor大概率会出现问题,不推荐,最好是用pip 安装, 注意python ...