flask link javascript code example

Example 1: where to put js files in flask

<script src="{{url_for('static', filename='somejavascriptfile.js')}}"></script>

Example 2: flask make static directory

from flask import Flask, send_from_directory

app = Flask(__name__)

@app.route("/static/<path:path>")
def static_dir(path):
    return send_from_directory("static", path)

if __name__ == "__main__":
    app.run()

Example 3: how to add js in flask

<script src="{{url_for('static', filename='js/modernizr-2.6.2.min.js')}}"></script>