External JavaScript file is not getting added when running on Flask External JavaScript file is not getting added when running on Flask flask flask

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="{{ url_for('static', filename='map.js') }}"></script>

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


Step 1:Create folder with name static on project root

Step 2:Add static files in static folder

Step 3Add in template

<script type="text/javascript" src="{{ url_for('static', filename = 'hello.js') }}"></script>


I experience the same issue, for stylesheet, the URL_FOR works but for javascript.I had to write

<script type="text/javascript" src="static/map.js"/>

It worked for me