title: How to serve static file from static folder using Flask
body: <p>I have the following Flask app, and I am trying to load a js file from a template:</p>
  <pre><code>from flask import Flask, request, send_from_directory, render_template
  
  # set the project root directory as the static folder, you can set others.
  app = Flask(__name__, static_url_path='')
  
  @app.route('/js/&lt;path:path&gt;')
  def send_js(path):
      return send_from_directory('js', path)
  
  @app.route(&quot;/&quot;)
  def main():
      return render_template('index.html')
  
  if __name__ == &quot;__main__&quot;:
      app.run()
  </code></pre>
  <p>Here is the folder:</p>
  <p><a href="https://i.stack.imgur.com/nsBJf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nsBJf.png" alt="enter image description here" /></a></p>
  <p>My index.html file does load but the js doesn't:</p>
  <pre><code>&lt;head&gt;
      &lt;script src=&quot;/static/js/asynckittens.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  
  
    hello world
  </code></pre>
  <p>I have tried it as <code>/js/asynckittens.js</code>, and even <code>/asynckittens.js</code> and nothing will load this file. How can I load a js file in a basic flask server?</p>