Skip to content
Advertisement

Passing variables from Flask to JavaScript

I looked at similar forums but was not able to get any of the solutions to work. I am trying to pass variables from Flask to my JavaScript file. These values then will be used for PubNub from my JavaScript file.

Here is part of my Python code:

JavaScript

Here is part of my JavaScript code (app.js):

JavaScript

this code works if I use it in my Settings.html file but not in the app.js file.

Advertisement

Answer

The mobiusklein answers is pretty good, but there is “hack” you should consider. Define your Javascript method to receive params and send data as params to your function.

main.py

JavaScript

app.js

JavaScript

settings.html

JavaScript
Advertisement