【发布时间】:2016-11-19 22:19:39
【问题描述】:
我正在尝试从列表中动态生成 Flask 中的路由。我想动态生成视图函数和端点,并用add_url_rule 添加它们。
这是我正在尝试做的,但我收到“映射覆盖”错误:
routes = [
dict(route="/", func="index", page="index"),
dict(route="/about", func="about", page="about")
]
for route in routes:
app.add_url_rule(
route["route"], #I believe this is the actual url
route["page"], # this is the name used for url_for (from the docs)
route["func"]
)
app.view_functions[route["func"]] = return render_template("index.html")
【问题讨论】: