static folder for css & js
simpletemplate3.py
from flask import * import random app = Flask(__name__) @app.route("/") def main(): if random.randint(1, 2) == 1: return render_template("basic.html", answer="salmon") else: return render_template("basic.html", answer="plum") app.run()
put basic.html into a templates folder:
templates\basic.html
<!doctype html> <link rel="stylesheet" href="{{ url_for('static', filename='some.css') }}"> <h1>Salmon or Plum?</h1><br> <h1>Python returned: {{answer}} </h1><br> <script src="{{ url_for('static', filename='some.js') }}"></script>
put css & js files into a static folder in the root python folder:
static\some.css
body{ background-color: rebeccapurple; }
static\some.js
alert("rebecca purple");