1

Sorry 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

Please send help & love!! Thanks

Eric Cai
  • 83
  • 2
  • 8

0 Answers0