mod_python

Little cookiecandyred at yahoo.com
Sun Nov 6 05:03:10 CET 2005


I have created the following database but the following errors occur
when trying to execute the code.

html source:
<html>
<body>
    Click here to display information from Chocolate menu:
<form action ="form.py/display" method="POST">
    <p>
    Press to view the display
    <input type="submit">
    </p>
</form>
<br>
    Please provide data for chocolate to be added:
<p>
<form action ="form.py/addchocolate" method="POST">
    <p>
    Name:        <input type="text" name="z_Name" maxlength="30"><br>
    Rating:      <input type="text" name="z_rating" maxlength="3"><br>
    Price :      <input type="text" name="z_price" maxlength="5"><br>
    <input type="submit">
    </p>
</form>
</body>
</html>

form.py source

import MySQLdb

def addchocolate(z_Name, z_rating, z_price):

    # make sure the user provided all the parameters
    if not (z_Name and z_rating and z_price):
        return "A required parameter is missing, \
               please go back and correct the error"
    db =
MySQLdb.connect(host="localhost",user="hayward",passwd="hayward",db="hayward")
    cursor = db.cursor()
    cursor.execute(
    """INSERT INTO InventoryList (artist, title, rating) VALUES (%s,
%s, %s)""", (z_Name, z_rating, z_price) )
    db.commit()
    cursor.close()
    db.close()

def display(rating):
    db =
MySQLdb.connect(host="localhost",user="hayward",passwd="hayward",db="hayward")
    cursor = db.cursor()
    cursor.execute("""SELECT * FROM InventoryList""")
    result = cursor.fetchall()
    cursor.close()
    db.close()
    parsesongs(result)
    return

def parsesongs(rawstring):
    print 'Chocolate Inventory'
    print
'---------------------------------------------------------------'
    print 'Name                       Rating
Price  '
    print
'---------------------------------------------------------------'
    for i in range (0, len(rawstring)):
        table = ''
        Name = rawstring[i][0]
        table = table + Name
        for j in range (0, (29 - len(Name))):
            table = table + ' '
        Rating = rawstring[i][1]
        table = table + Rating
        for k in range (0, (29 - len(Rating))):
            table = table + ' '
        Price = str(rawstring[i][2])
        table = table + Price
        print table
    print
'---------------------------------------------------------------'
    return

errors that occur
press display:
Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
193, in Dispatch
    result = object(req)

  File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line
173, in handler
    result = apply(object, (), args)

TypeError: display() takes exactly 1 argument (0 given)

press the addition of the items:
Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
193, in Dispatch
    result = object(req)

  File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line
173, in handler
    result = apply(object, (), args)

  File
"/home/hayward/public_html/Homework/Python_Executable_Publisher/form.py",
line 11, in addchocolate
    cursor.execute(

  File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line 137,
in execute
    self.errorhandler(self, exc, value)

  File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
33, in defaulterrorhandler
    raise errorclass, errorvalue

OperationalError: (1054, "Unknown column 'artist' in 'field list'")
 
Thanks for the help




More information about the Python-list mailing list