External JavaScript file is not getting added when running on Flask

前端 未结 4 839
孤独总比滥情好
孤独总比滥情好 2020-12-07 18:36

I have an HTML file named showMap.html:





  

        
相关标签:
4条回答
  • 2020-12-07 18:53

    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

    0 讨论(0)
  • 2020-12-07 18:55

    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') }}"/>

    0 讨论(0)
  • 2020-12-07 19:02

    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>
    
    0 讨论(0)
  • 2020-12-07 19:06

    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.

    0 讨论(0)
提交回复
热议问题