0

I'm trying to understand how flask works. i have this code with other stuff

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

I want to rename data in data0, data1, data2.. So I can pass data to my html page:

<!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>

But I keep get this error:

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

I have 29 links and I know just this method to pass everything, if there is some other method please tell me Thankyou.

fobu36
  • 49
  • 1
  • 5

1 Answers1

0

Have you tried to make it return a list instead of an expression? Something like this:

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)
user4700847
  • 164
  • 7