This lab is intended to get you started working with form input.
-
Create an XHTML form that allows a user to enter their name and their age. Name this file
age.html
. The "action" of this form should be the Python program you create below.Create a Python web script that takes the form data from that page. Name this file
result.py
. It should create XHTML with content like this (inside the<body>
):<p>Hello, name.</p>
<p>Next year, you will be X years old.</p>The word
name
should be replaced with the name the user entered. TheX
should be replaced with the age they entered plus one.In order to add one to the age the user enters, you will have to convert it to a number. This can be done with the int function, as in
int(form["age"].value)
. -
In this part you will check your
age.html
file and make sure it's valid.The XHTML code that your program generates should also be valid XHTML. That means (among other things) that your program will have to print out a doctype. You can check the validity in one of two ways.
When your page is online and functioning, you can copy-and-paste the URL with the query string to the validator. The URL will be something like this:
http://cmpt165.csil.sfu.ca/~userid/result.py?name=Your+Name&age=20
The other option is to view the result page, view the page source in your browser, and copy-and-paste the code into the "enter HTML code directly" section in a validator.
When you are done the above upload the files you created in this lab to the web-server. Create a text file named handin.txt
using your favourite text editor. Write your name, student number, SFU e-mail ID, and the URL of the form page you created above. You will submit this text file along with the python program result.py
to the submission server.