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"
<html xmlns="http://www.w3.org/1999/xhtml">
    <title>Product Discount Calculator</title>
    <link rel="stylesheet" type="text/css" href="main.css" />

    <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 id="buttons">
                <input type="submit" value="Calculate Discount" /><br />


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.

4 Years
Discussion Span
Last Post by snippsat

Cgi is pretty much dead in Python,and that's is very posetive.
Python community did make an all Python soution PEP 3333
So this is called WSGI(Web Server Gateway Interface),and is much better than cgi.
For small task like this is Flask and Bottle perfect.

Edited by snippsat

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.