OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Passing variables from Flask to JavaScript

  • Thread starter Thread starter pang
  • Start date Start date
P

pang

Guest
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:

Code:
@app.route("/mysettings/")
def user_settings(): 
        return render_template('Settings.html',  project_name = session['project_name'] , publish_key = session['publish_key'] , subscribe_key = session['subscribe_key'] )

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

Code:
var settings = {
        channel: {{project_name}},
        publish_key: {{publish_key}},
        subscribe_key: {{subscribe_key}}
    };

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

<p>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. </p>

<p>Here is part of my Python code: </p>

<pre><code>@app.route("/mysettings/")
def user_settings():
return render_template('Settings.html', project_name = session['project_name'] , publish_key = session['publish_key'] , subscribe_key = session['subscribe_key'] )
</code></pre>

<p>Here is part of my JavaScript code (app.js):</p>

<pre><code>var settings = {
channel: {{project_name}},
publish_key: {{publish_key}},
subscribe_key: {{subscribe_key}}
};
</code></pre>

<p>this code works if I use it in my Settings.html file but not in the app.js file.</p>
 
Top