title: Use Jinja2 template engine in external javascript file
body: <p>I working on a web project using Python and Flask. I was just wondering if I can access parameters sent by python in my external javascript files? It's working well with html files or with js embedded in html files but not when javascript is extern.</p>
  
  <p>See below.</p>
  
  <p>The python code</p>
  
  <pre><code>@app.route('/index')
  def index():
      return render_template('index.html', firstArg = 2, secondArg = 3)
  </code></pre>
  
  <p>The index.html code</p>
  
  <pre><code>...
  &lt;body&gt;
      &lt;p&gt;The first arg is {{firstArg}}.&lt;/p&gt;
      &lt;script src="index.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  ...
  </code></pre>
  
  <p>And the index.js file</p>
  
  <pre><code>window.onload=function(){
      console.log('{{secondArg}}');
  };
  </code></pre>
  
  <p>So the first arg is correct within the html file but the second doesn't work in the js file. The browser is showing <code>Unexpected token {</code>.</p>
  
  <p>Maybe it's not possible to use it in external js?</p>
  
  <p>Otherwise I would need to insert the secondArg as an input data in html and get it within the js file but it's not very clean.</p>
  
  <p>If someone can help, thanks.</p>