I have an HTML file named showMap.html
:
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
I want to add to Martijn's answer, that you have to link your js file exactly like this:
<script type="text/javascript" src="{{ url_for('static', filename='map.js') }}"></script>
and not like this:
<script type="text/javascript" src="{{ url_for('static', filename='map.js') }}"/>
Step 1: Create folder with name static on project root
Step 2: Add static files in static folder
Step 3 Add in template
<script type="text/javascript" src="{{ url_for('static', filename = 'hello.js') }}"></script>
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.