External Exam Download Resources Web Applications Games Recycle Bin

URL Routing


template.html:
<!doctype html>
<style>
    body{
        margin: 0px;
        padding: 0px;
    }
    #wrapper{
        margin: auto;
        width: 800px;
    }
    #header{
        margin-left: 300px;
    }
    #header a{
        width: 100px;
        float: left;
        background-color: peru;
    }
    #sidebar{
        clear: left;
        width: 20%;
        float: left;
        background-color:bisque;
    }
    #sidebar a{
        display: block;
        width: 100px;
    }
    #main{
        width: 80%;
        float: left;
        background-color:plum;
    }
    #footer{
        clear: both;
        text-align: center;
    }
    
</style>
<title>transport</title>
<body>
  <div id="wrapper">
    <div id="header">
          <a href="/train">train</a>
          <a href="/car">car</a>
    </div>
    <div id="sidebar">
        {% if transport=="train" %}
          <a href="/morning">morning</a>
          <a href="/afternoon">afternoon</a>
        {% elif transport=="car" %}
          <a href="/traffic">traffic</a>
        {% else %}
          &nbsp;
        {% endif %}
    </div>
    <div id="main">
        {% if transport=="train" and time is not defined %}
           choose train times from sidebar
        {% elif transport=="car" and time is not defined %}
           choose traffic link from sidebar
        {% elif transport=="train" and time=="morning" %}
           **morning train times here**
        {% elif transport=="train" and time=="afternoon" %}
           **afternoon train times here**
        {% elif transport=="car" and time=="traffic"%}
           **google maps traffic plugin here**
        {% else %}
           choose a mode of transport to get started
        {% endif %}
    </div>
    <div id="footer">&copy; me</div>
    </div>
</body>
site.py:
from flask import Flask, request, render_template
app = Flask(__name__)

@app.route("/")
def start():
    return render_template("template.html")

@app.route("/train")
def train():
    return render_template("template.html",
                           transport="train")

@app.route("/car")
def car():
    return render_template("template.html",
                           transport="car")

@app.route("/morning")
def morning():
    return render_template("template.html",
                           transport="train",
                           time="morning")

@app.route("/afternoon")
def afternoon():
    return render_template("template.html",
                           transport="train",
                           time="afternoon")

@app.route("/traffic")
def traffic():
    return render_template("template.html",
                           transport="car",
                           time="traffic")

app.run(host="0.0.0.0", port=5000, debug=True)

Challenges
create an app similiar to this one that displays your school timetable. skin it with a different GUI to the one i have used (to practise your web design skills). some links that may help: