<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Home</title>
<link rel="stylesheet" type="text/css" href="{{url_for("static",filename="css/css.css")}}">
</head>
<body>
<h1>Welcome to recipe book</h1>
<p>{{length}}</p>
<script>
const amount = {{length}};
console.log(amount);
</script>
</body>
</html>
#,redirect,url_for,send_from_directory,
from flask import Flask,render_template
import os
app = Flask(__name__)
@app.route("/")
def home():
parent = r"C:UserskhaitDesktopWebsiteRecipe_Bookstaticimages"
everything = os.listdir(parent)
images = []
for i in everything:
if os.path.isfile(os.path.join(parent,i)):
images.append(os.path.join(parent,i))
length = len(images)
return render_template("Home.html",images=images,length=length)
if __name__ == "__main__":
app.run(debug=True)`
i was just tryna use the length variable in my html. and it throws these errors in relation to this line: “const amount = {{length}};”:
Error 1:
Property assignment expected.javascript
Error 2:
Declaration or statement expected.javascript
I am aware many similar questions have been asked on this but i looked through them and couldn’t find an answer to my problem. Any help would be greatly appreciated.