【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/ ...
随机推荐
- dell服务器raid设置
dell服务器raid设置 配置说明: 开机自检按ctrl+R键进入配置界面 如果服务器有raid卡,而不想做磁盘阵列时,需要做单盘RAID0,主要是为了让卡来识别一下硬盘 对raid进行操作很可能会 ...
- CentOS7切换源
1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2.下载新的CentOS-Base ...
- 从输入URL到页面加载的全过程
前面的话 本文将详细介绍从输入URL到页面加载的全过程 概述 从输入URL到页面加载的主干流程如下: 1.浏览器构建HTTP Request请求 2.网络传输 3.服务器构建HTTP Response ...
- Azure DevOps to Azure AppServices
Azure DevOps is a complete solution for software development, from planning to building to deploymen ...
- java篇 之 流程控制语句
条件判断语句 条件语句: If(boolean类型) {} else {} (打大括号避免出错) switch (export)语句:export的类型必须是 byte,short,char,i ...
- Spring Cloud 微服务
https://mp.weixin.qq.com/s?__biz=MzU0OTE4MzYzMw==&mid=2247486301&idx=2&sn=f6d45860269b61 ...
- 我眼中的Adaboost
步骤: def buildStump(dataArr,classLabels,D): 1.循环取出数据集中的一个特征(一列)输入 (for:) 2.循环调整阀值threshVal (for:) 3, ...
- 关于 iOS 性能优化方面的面试题,
这是我前面几天碰到的面试题: 如何对定位和分析项目中影响性能的地方?以及如何进行性能优化? 我的答案: 定位方法: instruments 在iOS上进行性能分析的时候,首先考虑借助instrum ...
- 第一个thinkphp项目遇到的知识
本文是于项目完成后所写,基本是想到 哪写到哪,所以顺序会很乱. 1.在后台处理ueditor这种文本编辑器的时候,会遇到取值问题,如果你想要取纯文本内容:getContentTxt(),没有段落格式: ...
- Httpclient发送json请求
一.Httpclient发送json请求 public String RequestJsonPost(String url){ String strresponse = null; try ...