Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python AssertionError:视图函数映射正在覆盖现有端点函数:空?_Python_Flask - Fatal编程技术网

Python AssertionError:视图函数映射正在覆盖现有端点函数:空?

Python AssertionError:视图函数映射正在覆盖现有端点函数:空?,python,flask,Python,Flask,任何关于清洁解决方案的建议都将不胜感激 我正在尝试将一些静态文件添加到现有应用程序中,已设置包含其他文件的静态文件夹。我想根据列表定义几个路由,目标是能够轻松添加文件 问题是,我收到的不是工作程序,而是“端点函数”没有被正确检测到 输出: {'/file1.js': <function func at 0x10aedfed8>, '/file2.js': <function func at 0x10aeea050>} {'/file1.js': <functio

任何关于清洁解决方案的建议都将不胜感激

我正在尝试将一些静态文件添加到现有应用程序中,已设置包含其他文件的静态文件夹。我想根据列表定义几个路由,目标是能够轻松添加文件

问题是,我收到的不是工作程序,而是“端点函数”没有被正确检测到

输出:

 {'/file1.js': <function func at 0x10aedfed8>, '/file2.js': <function func at 0x10aeea050>}
 {'/file1.js': <function func at 0x10aedfed8>, '/file2.js': <function func at 0x10aeea050>}
 Traceback (most recent call last):
   File "flaskweird.py", line 29, in <module>
     app.add_url_rule(d, '', app.serv_deps[d])
   File "/Library/Python/2.7/site-packages/flask/app.py", line 62, in wrapper_func
     return f(self, *args, **kwargs)
   File "/Library/Python/2.7/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:
要提供的示例文件:

mkdir ui
echo "test1" > ui/file1.js
echo "test2" > ui/file2.js
Flask==0.10.1

“因为您在for循环中多次将空字符串传递给
add\u url\u rule
。每次都选择一个唯一的名称。”--davidism

这个很好用

for d in deps:
    app.add_url_rule(d, d, app.serv_deps[d])

谢谢

您是否考虑过使用Flask's引入其他静态文件源?嗯。。。谢谢,看来行得通,我试试看。知道为什么假定被重写的函数名是空的吗?
for d in deps:
    app.add_url_rule(d, d, app.serv_deps[d])