Home > Article > Backend Development > How to Pass Data from Flask to JavaScript in Templates for Google Maps API?
Your Flask application requires passing information from a Python dictionary to JavaScript in a template, particularly for the Google Maps API.
Render_template in Flask provides a mechanism to pass variables to templates for HTML rendering. To extend this functionality to JavaScript, you can leverage the Jinja templating engine. Here's how:
<code class="javascript"><script> var longitude = '{{ geocode[1] }}'; </script></code>
<code class="html"> <script> var geocode = ['{{ geocode[0] }}', '{{ geocode[1] }}']; </script></code>
<code class="html"><script> var geocode = [{{ ', '.join(geocode) }}]; </script></code>
<code class="html"> <script> var geocode = {{ geocode | tojson }}; </script></code>
The above is the detailed content of How to Pass Data from Flask to JavaScript in Templates for Google Maps API?. For more information, please follow other related articles on the PHP Chinese website!