CS1116/CS5018

Web Development 2

Dr Derek Bridge

School of Computer Science & Information Technology

University College Cork

colour.html: a page with a form

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Mint tint</title>
    </head>
    <body>
        <form action="colour.py" method="get">
            <p>What's Derek's favourite colour?</p>
            <input type="radio" name="guess" value="red" id="red" checked />
            <label for="red">Red</label>
            <input type="radio" name="guess" value="green" id="green" />
            <label for="green">Green</label>
            <input type="radio" name="guess" value="blue" id="blue" />
            <label for="blue">Blue</label>
            <input type="submit" value="Hit me!" />
        </form>
    </body>
</html>

colour.py: an incomplete program

#!/usr/local/bin/python3
            
from cgitb import enable
enable()

from cgi import FieldStorage

print('Content-Type: text/html')
print()

dereks_mint_tint = 'green';

form_data = FieldStorage()

print("""
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <title>Mint tint</title>
        </head>
        <body>
            <p>
                You are %s. Derek's favourite colour is %s.
            </p>
        </body>
    </html>""" % (outcome, dereks_mint_tint))

toppings.html: a page with a form

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Top toppings</title>
    </head>
    <body>
        <form action="toppings.py" method="get">
            <p>What are Derek's favourite pizza toppings?</p>
            <input type="checkbox" name="guesses" value="anchovies" id="anchovies" />
            <label for="anchovies">Anchovies</label>
            <input type="checkbox" name="guesses" value="chocolate" id="chocolate" />
            <label for="chocolate">Chocolate</label>
            <input type="checkbox" name="guesses" value="nails" id="nails" />
            <label for="nails">Finger nails</label>
            <input type="checkbox" name="guesses" value="olives" id="olives" />
            <label for="olives">Olives</label>
            <input type="checkbox" name="guesses" value="pepperoni" id="pepperoni" />
            <label for="pepperoni">Pepperoni</label>
            <input type="submit" value="Dish it up!" />
        </form>
    </body>
</html>

toppings.py: an incomplete program

#!/usr/local/bin/python3

from cgitb import enable 
enable()

from cgi import FieldStorage

print('Content-Type: text/html')
print()

dereks_top_toppings = ['anchovies', 'chocolate', 'pepperoni']

form_data = FieldStorage()

print("""
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <title>Top toppings</title>
        </head>
        <body>
            <p>
                %s
            </p>
        </body>
    </html>""" % (outcome))

Summary

Summary