Reputation: 1794
I have a python/flask application that I'm creating. I am also using javascript on some parts of it. The current setup I have is that when I render the template, I pass along any additional javascript that needs to be on the page.
@app.route('/index')
def index():
return render_template('index.html',
more_js = '/static/js/example.js',
more_js_script = 'example_js_to_execute();')
It ends up on the page that more_js is the src of a script tag and more_js_script is executed in a script tag. Is there a better way to do this? There's also times I need to pass a parameter to the more_js_script that is a string, but because of the formatting
more_js_script = 'example_js_to_execute('parameter');
will end up like
<script>example_js_to_execute('parameter');</script>
on the actual page and not execute correctly. Do you have any tips on how to restructure what I'm doing or execute what I have with parameters?
Upvotes: 1
Views: 630
Reputation: 487
Make more_js_script
not to be automatic escaping.
http://jinja.pocoo.org/docs/templates/#working-with-automatic-escaping
Upvotes: 1