I'm trying to make a calculator of a sort in python that works on a local web server. I have the localhost all set up and all.
import cgi
data = cgi.FieldStorage()
product_description = data.getvalue('product_description')
list_price = data.getvalue('list_price')
discount_percent = data.getvalue('discount_percent')
total = data.getvalue('total')
def total_price():
data.getvalue('total') - discount
return data.getvalue('total')
print( 'Content-type:text/html\r\n\r\n' )
print( '<!DOCTYPE HTML>' )
print( '<html lang="en">' )
print( '<head>' )
print( '<meta charset="UTF-8">' )
print( '<title>Product Discount Calculator</title>' )
print( '</head>' )
print( '<body>' )
print( '<h1>Product Description:', product_description,'</h1>' )
print( '<h1>List Price:', list_price, '</h1>' )
print( '<h1>Discount:', discount_percent, '</h1>' )
print( '<h1>Subtotal:', total, '</h1>' )
print( '</body>' )
print( '</html>' )
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Product Discount Calculator</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>
<body>
<div id="content">
<h1>Product Discount Calculator</h1>
<form action="display_discount.py" method="post">
<div id="data">
<label>Product Description:</label>
<input type="text" name="product_description"/><br />
<label>List Price:</label>
<input type="text" name="list_price"/><br />
<label>Discount Percent:</label>
<input type="text" name="discount_percent"/>%<br />
</div>
<div id="buttons">
<label> </label>
<input type="submit" value="Calculate Discount" /><br />
</div>
</form>
</div>
</body>
</html>
The above are the html files and the python file. Every time I add any if statements or anything into the python file, it just comes up with a Internal Server Error. So I need help with trying to to figure out how to calculate percentage, the price, etc so that it works through the webserver.