I have followed this post to send data from flask to a JS file.
Flask:
@app.route('/')
def home():
content = "Hello"
return render_template('index.html', content=content)
HTML
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script src='static/app.js'></script>
<meta id="my-data" data-name="{{content}}">
</body>
JS/JQuery
var djangoData = $('#my-data').data();
I have also tried var djangoData = $('#my-data').data('content');
Nonethless, I get:
typeof djangoData
"undefined"
In the console.
I was also curious to know if this method is still considered as best practice, if not what is, as I know there are many ways of sending data from FLASK to JS.
Thanks :)