Flask Template II - Static Files

#mkdir static file dir and store static files in it
mkdir
static

vi static/hello2.js

function sayHello() {
  alert("Hello. :)")
}
vi templates/hello2.html
<html>
  <head>
    <script type = "text/javascript"
       src = "{{ url_for('static', filename = 'hello2.js') }}" ></script>
  </head>

  <body>
    <input type = "button" onclick = "sayHello()" value = "Say: Hello" />
  </body>
</html>
vi hello2.py
from flask import Flask, render_template
ap = Flask(__name__)

@ap.route("/hello")
def index():
  return render_template("hello2.html")

if __name__ == '__main__':
  ap.run(host='0.0.0.0')




Leave comments

authimage

Copyright(c) 2017 - PythonBlogs.com
By using this website, you signify your acceptance of Terms and Conditions and Privacy Policy
All rights reserved