gandalf458
IS-IT--Management
Hi. I'm new to Python, trying to teach myself. I have the following script which works fine but I'm wondering if there are better ways of doing some things.
The page that calls this script is at if that helps.
Thanks
I'm not a number, I'm a free man
Code:
print("Content-type:text/html\r\n")
import cgi, cgitb
form = cgi.FieldStorage()
# Get data from form fields
# text fields
tname = form.getvalue('tname')
tdate = form.getvalue('tdate')
# textarea
if form.getvalue('comments'):
comments = form.getvalue('comments')
else:
comments = "None"
# checkbox
if form.getvalue('certificate'):
checkbox1 = "yes"
else:
checkbox1 = "no"
if form.getvalue('alumni'):
checkbox2 = "yes"
else:
checkbox2 = "no"
# radio button
if form.getvalue('grade'):
grade = form.getvalue('grade')
else:
grade = "Not set"
# dropdown
if form.getvalue('subject'):
subject = form.getvalue('subject')
else:
subject = "Not entered"
aoran = "a "
if (grade == "ordinary") or (grade == "upper second"):
aoran = "an "
if ( grade != "ordinary" ):
grade = grade + ' class honours'
print("""<!doctype html>
<html lang="en-gb">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Certificate</title>
</head>
<body>
<style>
body {
font: .92em Verdana, Arial, Helvetica, sans-serif;
text-align: center;
}
div {
width: 20em;
margin: 2em auto;
padding: 2em;
border: 1px solid black;
}
</style>
<div>""")
print("<h1>Certificate</h1>")
print("<h2>This is to certify that</h2>")
print("<h3> %s </h3>" % (tname))
print("<p>has been awarded</p>")
print("<p> %s %s degree</p>" % (aoran, grade))
print("<p>in %s </p>" % (subject))
print("<p>Date: %s </p>" % (tdate))
print("<p>Comments: %s </p>" % (comments))
print("<p>--- for official use ---<br>certificate: %s; alumni: %s </p>" % (checkbox1, checkbox2))
print("""</div>
</body>
</html>""")
The page that calls this script is at if that helps.
Thanks
I'm not a number, I'm a free man