运行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. [转帖]Zoom

    Zoom美国上市:华裔创始人为大股东 创业想法来自“异地恋” https://baijiahao.baidu.com/s?id=1631166070308020680&wfr=spider&a ...

  2. 特殊计数序列——第二类斯特林(stirling)数

    计算式 \[ S(n,m)=S(n-1,m-1)+mS(n,m) \] \(S(0,0)=1,S(i,0)=0(i>0)\) 组合意义 将\(n\)个不可分辨的小球放入\(m\)个不可分辨的盒子 ...

  3. 简单 php 代码跟踪调试实现

    简单 php 代码跟踪调试实现 debug_backtrace:生成回溯 debug_print_backtrace:打印回溯 1. debug_backtrace ($options = DEBUG ...

  4. 自动化测试框架【linux版】:JMeter + Ant + Jenkins

    前提条件:linux安装了jmeter.ant.jenkins 安装方法参考汇总目录中对应的博文 截图看不清的,可以调大浏览器倍数看 jenkins驱动ant执行,ant驱动jmeter执行 ant调 ...

  5. Codeforces Global Round 1 A~F

    失踪人口回来写题了.. 写了几乎一下午.贴一贴代码以及口糊一下. A. 题意:计算一下这个多项式的和. 题解:暴力算一算对每一项异或一下. #include<bits/stdc++.h> ...

  6. EnableFeignClients基本配置

    pom.xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId&g ...

  7. 分布式锁与实现(一)——基于Redis实现 【比较靠谱】

    转: 分布式锁与实现(一)——基于Redis实现 概述 目前几乎很多大型网站及应用都是分布式部署的,分布式场景中的数据一致性问题一直是一个比较重要的话题.分布式的CAP理论告诉我们“任何一个分布式系统 ...

  8. jemter+ant+jenkins进行集成测试

    一下为我学习的一些笔记: 一.安装配置ant 安装地址:http://ant.apache.org/ 1.下载ant一路傻瓜式安装 2.配置ant环境变量:path下配置ant的bin路径 3.将jm ...

  9. Cmake出现CMake Error: Could not find CMAKE_ROOT !!!

    试了很多方式, 其实只需要这一句话!!!!!! hash -r

  10. SQL Server 游标的使用示例

    Ø  简介 本文主要记录 MSSQL 中的游标使用示例,在有必要时方便借鉴查阅.游标一般定义在某段功能性的 SQL 语句中,或者存储过程中.之所以选择用它,是因为有时候无法使用简单的 SQL 语句满足 ...