View Single Post
Old October 27th, 2007   #17
smartbei
Has an Ubuntu Drip
 
smartbei's Avatar
 
Join Date: Nov 2006
Location: Israel
Beans: 703
Ubuntu 9.04 Jaunty Jackalope
Re: Making a web page

Ok, I was interested and having fun looking this up, so I made a small demo page... You can find it running here

The actual code for that is:
Code:
#!/usr/bin/python
import cgi

def main():
	print "Content-type: text/html\n\n" #necessary!!! without this it wont work
	form=cgi.FieldStorage() #initialize the form storage for getting data from the user
	name=form.getfirst("name") #get the name from the user (through the form)
	if name != None:
		name=nameProcess(name) # save processed name
	else:
		name="No name input :(" #no name given...
	
	# This is the actual page:
	print """
	<html>
	<head>
	<title>Name Perioder</title>
	</head>
	<body>
	<h1>%s</h1>
	<form action="" method="get">
	<input type="text" name="name">
	<input type="submit">
	</form>
	</body>
	</html>""" % name #string formatting - insert the name into the page

def nameProcess(orig): #function to be called on user input. Inserts a dot after each letter.
	final=""
	for a in orig:
		final+=a+"."
	return final

if __name__ == "__main__": #checks to make sure that this page isn't included by another. if it is, we wouldn't want it to print the contents of main().
    main()
Not the most elegant, but I think it illustrates the basic point.
__________________
Intel E6300 / MSI P4M890M / 2GB DDR2 677 / 80GB SATA2 / GeForce 6200TC / DL DVD+-RW / ViewCom 17" LCD

Last edited by smartbei; November 3rd, 2007 at 04:28 PM..
smartbei is offline   Reply With Quote