运行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的更多相关文章

  1. "AssertionError: View function mapping is overwriting an existing endpoint function"如何解决

    使用Flask定义URL的时候,如果出现"AssertionError: View function mapping is overwriting an existing endpoint ...

  2. Flask之endpoint错误View function mapping is overwriting an existing endpoint function: ***

    最近在学习Flask, 其中遇到了一个错误, 发现这个问题和Flask, 路由有关系, 所以就记了下来 错误代码: from flask import Flask, render_template, ...

  3. AssertionError: View function mapping is overwriting an existing endpoint function: insertCase

    首先,理解这个错误是什么意思,以及出现的原因: 使用Flask定义URL的时候,如果出现"AssertionError: View function mapping is overwriti ...

  4. AssertionError: View function mapping is overwriting an existing endpoint function: admin.main

    刚才给views.py文件添加了一个路由地址: @admin_view.route('/test', methods=["get", "post"]) @log ...

  5. MyEclipse Server view报错解决方法

    MyEclipse Server view报错解决方法 方法/步骤     启动MyEclipse,弹出一个框,报错. ---------------------------------------- ...

  6. eclipse创建的maven项目,pom.xml文件报错解决方法

    [错误一:]maven 编译级别过低 [解决办法:] 使用 maven-compiler-plugin 将 maven 编译级别改为 jdk1.6 以上: <!-- java编译插件 --> ...

  7. Loadrunner参数化逗号报错解决方法

    Loadrunner参数化逗号报错解决方法     介绍Loadrunner参数化时,参数中包含有逗号时出错的解决方法. 在Loadrunner进行参数化时,参数中如果含有逗号,编辑保存后会报错: 此 ...

  8. 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 ...

  9. iOS url带中文下载时 报错解决方法

    问题描述:下载文件时, 请求带中文的URL的资源时,比如:http://s237.sznews.com/pic/2010/11/23/e4fa5794926548ac953a8a525a23b6f2/ ...

随机推荐

  1. 基于 docker 的yapi(快速部署)

    1.使用官方的mongodb镜像 docker run --network yapi_net --ip 172.30.0.10  -d --name yapi_mongodb --restart al ...

  2. python 绘制柱状图

    python 绘制柱状图 import matplotlib.pyplot as plt import numpy as np # 创建一个点数为 8 x 6 的窗口, 并设置分辨率为 80像素/每英 ...

  3. P3373 【模板】线段树 2

    线段树的模板,但是还应注意维护乘标记,乘法的优先级大于加法,一定记得还要取模. #include<bits/stdc++.h> using namespace std; ; struct ...

  4. DAY22、面向对象

    一.复习:1.面向过程与面向对象 过程:程序流程化,可拓展性差 对象:程序流程多样化,可拓展性强 面向对象引入属性 | 方法的概念,通过所属者.语法调用2.拥有名称空间的对象:有__dict__属性, ...

  5. HDU 4547 CD操作

    传送门 没啥好说的.就是一个LCA. 不过就是有从根到子树里任意一个节点只需要一次操作,特判一下LCA是不是等于v.相等的话不用走.否则就是1次操作. 主要是想写一下倍增的板子. 倍增基于二进制.暴力 ...

  6. Go语言中的方法和函数

    在C#或者Java里面我们都知道,一个Class是要包含成员变量和方法的,对于GO语言的Struct也一样,我们也可以给Struct定义一系列方法. 一.怎么定义一个方法? Go的方法是在函数前面加上 ...

  7. nginx--default_server定义规则及配置

    nginx 的 default_server 指令可以定义默认的 server 出处理一些没有成功匹配 server_name 的请求,如果没有显式定义,则会选取第一个定义的 server 作为 de ...

  8. TCP/IP的四元组、五元组、七元组

    TCP/IP的四元组.五元组.七元组 四元组是: 源IP地址.目的IP地址.源端口.目的端口 五元组是: 源IP地址.目的IP地址.协议号.源端口.目的端口 七元组是: 源IP地址.目的IP地址.协议 ...

  9. 「POI2011 R2 Day2」Tree Rotations【线段树合并】

    题目链接 [BZOJ] [洛谷] [LOJ] 题解 由于是前序遍历,那么讨论一棵树上的逆序对的情况. 两个节点都在左子树上 两个节点都在右子树上 两个节点分别在不同的子树上. 前两种情况其实也可以归结 ...

  10. Motorola和Intel格式报文解析的区别

      结论:无论用的Motorola,还是Intel格式,只在单个信号跨字节时解析才有区别. 先看下Vector的CANoe中dbc编辑器是如何呈现报文的: 图1 CAN报文中byte与bit顺序 从图 ...