I am really new to Flask, and I have encountered this issue while I was trying to pass data from Python Flask to JS in the front end:
app.py
@app.route("/",methods=['POST', 'GET'])
def search():
data = {"username": "test", "site": "stackoverflow.com"}
return render_template('search.html',data=data)
search.html
<html>
<head>
<script type="text/javascript" src="{{url_for('static', filename='js/search.js')}}"></script>
</head>
<body>
</body>
</html>
search.js
console.log(data)
and the result I got from the console was
ReferenceError: data is not defined
I have checked out this question, and that one still can't address the issue in this case, I tried. What is the main issue here? Is it a syntax issue? Or data formatting issue?