运行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. How do I copy files that need root access with scp

    server - How do I copy files that need root access with scp? - Ask Ubuntuhttps://askubuntu.com/quest ...

  2. web 应用常见安全漏洞

    1. SQL 注入 SQL 注入就是通过给 web 应用接口传入一些特殊字符,达到欺骗服务器执行恶意的 SQL 命令. SQL 注入漏洞属于后端的范畴,但前端也可做体验上的优化. 原因 当使用外部不可 ...

  3. CentOS7桌面版系统使用的一些小技巧

    1. 清空~/.kde/ 文件下的文件,登陆后不显示桌面的解决方法 在使用CentOS7 桌面系统时,有时候打开文件会很卡.这时我们需要清空当前用户下的 .kde 文件下的所有文件. 再重新登陆该用户 ...

  4. linux环境下在springboot项目中获取项目路径(用于保存文件等)

    //application.properties中设置:(file.path=static/qrfile/)//保存到static文件夹下的qrfile目录@Value("${file.pa ...

  5. eclipse mars2在高分辨率下(macpro)图标极小的问题

    Mac Pro装WIN10和Surface Pro同样有效 安装了Eclipse并且打开之后,发现图标显示极其细小,肉眼几乎无法看清了.这是由于Eclipse对高分屏没有作适配导致的. Windows ...

  6. 【pytorch】关于Embedding和GRU、LSTM的使用详解

    1. Embedding的使用 pytorch中实现了Embedding,下面是关于Embedding的使用. torch.nn包下的Embedding,作为训练的一层,随模型训练得到适合的词向量. ...

  7. 《AutoCAD Civil 3D .NET二次开发》勘误1

    第十三章atc文件中Displayname应为DisplayName,注意Name的N为大写,否则参数名称无法正常显示. 给您带来的不便深表歉意!

  8. [搬运] 将 Visual Studio 的代码片段导出到 VS Code

    原文 : A Visual Studio to Visual Studio Code Snippet Converter 作者 : Rick Strahl 译者 : 张蘅水 导语 和原文作者一样,水弟 ...

  9. ubuntu下使用ss-qt5

    第一步:.安装ss-qt5 通过PPA源安装,仅支持Ubuntu 14.04或更高版本. 打开终端 sudo add-apt-repository ppa:hzwhuang/ss-qt5 sudo a ...

  10. webp图片实践之路(转载)

    最近,我们在项目中实践了webp图片,并且抽离出了工具模块,整合到了项目的基础模板中.传闻IOS10也将要支持webp,那么使用webp带来的性能提升将更加明显.估计在不久的将来,webp会成为标配. ...