Lab #6 = Homework #6 The purpose of today's lab (and homework) is to introduce you to web page construction, with the twist that you will write a python program that generates a tailored web page for the user.
Part 1. First, you will create a simple web page and go through all of the steps to "publish" it in your account on beowulf. Then you will learn how to use python to create a page. The language that browsers can interpret is called html, or hyper-text markup language.
<html> <head> <title>A Simple Web Page</title> </head> <body> <H2>A web page with an image</H2> <IMG SRC="taz.gif" WIDTH=130 HEIGHT=130>The Tasmanian Devil</img> </body> </html>
getcopy taz.gif
cp lab6.html public_html/lab6.html cp taz.gif public_html/taz.gifand make sure they are accessible to all web users by typing
chmod a+r public_html/*.*
cd public_htmlwhere cd stands for change directory. Then do what you usually do: emacs lab6.py, etc.
myhtmlfile = open("lab6user.html","w")
and make sure you use write ("w") mode.
myhtmlfile.write("" + "\n")
Try getting your program first to write the simple html file
above before adding the other parts described below.
The <img ...> tag is a little tricky, because
the double quotes are necessary for the html img tag, to tell it
the filename of the image. There are two solutions:
You can use single quotes for the whole string,
and so will pass the write() function
this string as a paramter:
'<IMG SRC="taz.gif" WIDTH=130 HEIGHT=130>The Tasmanian Devil</img>'or you can use double quotes for the whole string and use the special double quote character \":
"<IMG SRC=\"taz.gif\" WIDTH=130 HEIGHT=130>The Tasmanian Devil</img>"When you are done editing, have run python, and python has created your lab6user.html file, it will already be in the right directory (public_html). Don't forget to
chmod a+r lab6user.html
choice = raw_input("Which one (Darth, Franklin, or taz)? ")
You should be careful in case the user doesn't capitalize one of them,
and also, make the third one the default so your program generates
an html file with an image on it no matter what.
Use string concatenation(+) to
create the string that contains the image filename.
<IMG SRC="taz.gif" WIDTH=130 HEIGHT=130>The Tasmanian Devil</img>
<html> <head> <title>A Simple Web Page</title> </head> <body>to the file. Then you will call this function in your main function definition in the place where you want these tags to be written to your file.
</body> </html>to the file. Then you will call this function in your main function definition in the place where you want these tags to be written to your file.
This lab is this week's homework. When you are done with it, by midnight Wednesday October 18.
submit homework6 lab6.pyAlso! make sure to submit the three gif images, for example:
submit homework6 Darth.gifDon't forget to use sftp to make sure that each partner has a copy of the files.