External JavaScript file is not getting added when running on Flask

Serve the map.js file as a static resource:

  • move the file to a static/ subdirectory of your package

  • generate a static URL for it in a Jinja2 template like so:

     <script type="text/javascript"
             src="https://stackoverflow.com/questions/14711552/{{ url_for("static', filename="map.js") }}"></script>
    

The filename parameter takes a relative path; you can use subdirectories was needed.

Leave a Comment