此函数的别名或任何其他将url与flas链接的方法

2024-05-19 21:38:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道烧瓶是怎么工作的。 我有这个代码和其他东西

@app.route("/")
def profile():
    for i in range(28):
        return render_template("profile.html",(data + str(i))=posts_to_chose[i])
        i+=1

我要重命名数据0、数据1、数据2中的数据。。 因此我可以将数据传递到我的html页面:

<!DOCTYPE html>
<html lang="en">

<body>

    <img src= {{data0}} title= "Title of image alt=" alt text here”>
    <img src= {{data1}} title= "Title of image alt=" alt text here”>
    <img src= {{data2}} title= "Title of image alt=" alt text here”>
    ...
    <img src= {{data_n}} title= "Title of image alt=" alt text here”>

</body>
</html>

但我一直有个错误:

return render_template("profile.html",(data + str(i))=posts_to_chose[i])
                                     ^
SyntaxError: keyword can't be an expression

我有29个链接,我只知道这个方法通过一切,如果有其他方法请告诉我 谢谢你。你知道吗


Tags: of数据textimagesrcimgdatareturn
1条回答
网友
1楼 · 发布于 2024-05-19 21:38:15

你试过让它返回一个列表而不是一个表达式吗?像这样:

def profile():
    posts_to_chose=[]
    for i in range(29):
        posts_to_chose.append((data[i] + str(i)))
        i+=1
    return posts_to_chose

return render_template("profile.html", posts_to_chose)

相关问题 更多 >