任何有关清洁解决方案的建议都将受到赞赏。
我正在尝试向现有应用添加一些静态文件,已经设置了包含其他文件的静态文件夹。我想基于列表定义几个路由,目标是能够轻松添加文件。
问题是我收到此而不是工作程序,未正确检测到“端点功能”。
输出:
public class PERSOON{
public DateTime gebd {get;set;}
}
代码:
{'/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:
要投放的示例文件:
from flask import Flask
app = Flask(__name__)
def gen_serv_dep(path):
fp = 'ui' + path # path always starts with /
with open(fp) as f:
content = f.read()
if path.endswith('.css'):
mime = "text/css"
elif path.endswith('.js'):
mime = "text/javascript"
else:
mime = "text"
def func():
#this.__name__ = path # doesn't change anything
return Response(response=content, status=200, mimetype=mime)
return func
deps = ['/file1.js', '/file2.js']
app.serv_deps = {}
for d in deps:
app.serv_deps[d] = gen_serv_dep(d)
for d in deps:
print(app.serv_deps)
app.add_url_rule(d, '', app.serv_deps[d])
@app.route('/')
def hello_world():
return 'Hello, World!'
烧瓶== 0.10.1
答案 0 :(得分:0)
“因为您在for循环中多次将空字符串传递给add_url_rule
。每次都选择一个唯一的名称。” - 大卫
这很好用
for d in deps:
app.add_url_rule(d, d, app.serv_deps[d])
由于