External Exam Download Resources Web Applications Games Recycle Bin

Simple Template


create templates folder in root of flask app:

templates folder

save template.html file into templates folder:
<!doctype html>
<title>is salmon cool?</title>
{% if colour=="salmon" %}
<h1 style="color:salmon;">how good is salmon!</h1>
{% else %}
<h1 style="color:blue;">you chose {{ colour }}</h1>
{% endif %}
and flask source code:
from flask import Flask
from flask import render_template
app = Flask(__name__)

@app.route("/")
def urlTriggerThis():
    return render_template('template.html', colour="salmon")

app.run(host= '0.0.0.0')
uses Jinja2 templates


challenges
  1. add image of coin face to coin flip app
  2. create an app that gives me a 3 x 3 visual grid of numbers 1 through 9. the ordering of the numbers is randomised every time i hit refresh