本文介绍了AssertionError:视图函数映射覆盖现有的端点函数:main的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道为什么我不能覆盖现有的端点函数,如果我有这样的两个url规则
Does anyone know why I can't overwrite an existing endpoint function if i have two url rules like this
app.add_url_rule('/',
view_func=Main.as_view('main'),
methods=["GET"])
app.add_url_rule('/<page>/',
view_func=Main.as_view('main'),
methods=["GET"])
追溯:
Traceback:
Traceback (most recent call last):
File "demo.py", line 20, in <module> methods=["GET"])
File ".../python2.6/site-packages/flask/app.py",
line 62, in wrapper_func return f(self, *args, **kwargs)
File ".../python2.6/site-packages/flask/app.py",
line 984, in add_url_rule 'existing endpoint function: %s' % endpoint)
AssertionError: View function mapping is overwriting an existing endpoint
function: main
推荐答案
您的视图名称即使指向相同的视图方法也必须是唯一的。
Your view names need to be unique even if they are pointing to the same view method.
app.add_url_rule('/',
view_func=Main.as_view('main'),
methods = ['GET'])
app.add_url_rule('/<page>/',
view_func=Main.as_view('page'),
methods = ['GET'])
这篇关于AssertionError:视图函数映射覆盖现有的端点函数:main的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!