我是Flask的新手。我理解下一个代码,我认为将文章变量传递给模板articles.html
@app.route('/articles')
def articles():
return render_template("articles.html", articles=Articles)
但是下面的一个是我不明白的:
@app.route('/articles/<string:id>/')
def article(id):
return render_template("article.html", id=id)
有人可以解释一下吗? "<string:id>"
和参数id
在funcion文章中的含义以及id
。提前致谢!
在Flask中,/articles/<string:id>/
指定了一个路径参数,以便在向例如
/articles/123/
变量id
的值为123
- 作为字符串,因为这是指定的类型。
因此,对于任何给定的文章名称,这将传递给渲染以与article.html
一起使用。