擅长:python、mysql、java
<p>这就是我让它在@This vidor和@PZP下工作的方法,get page方法正在查询sqlite数据库(但它可以是任何数据库),泛型函数def正在循环,在我的实际字典代码列表中,字典也正在从数据库中提取。所以基本上我完成了我需要的。路线是动态的。我可以在sql中打开和关闭路由,而不必去app.py编辑它们。</p>
<pre><code>defaultPage = "/"
@app.route(defaultPage)
def index():
page = getPage(defaultPage)
return render_template("index.html", page=page)
routes = [
dict(route="/", func="index", page="index"),
dict(route="/about", func="about", page="about")
]
def generic():
rule = request.url_rule
page = getPage(rule)
return render_template('index.html', page=page)
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)
)
app.view_functions[route["func"]] = generic`
</code></pre>