Wed Development - Dynamically Generated News Index

infidel02 at lycos.com infidel02 at lycos.com
Tue Dec 20 23:01:53 CET 2005


Hi Jean-Paul,

The truth of the matter is that I was hoping that this could be
accomplished using pure CGI.

I am considering wether I need to learn these new frameworks, but I am
in somewhat of a hurry.

Also I have this problem with this simple test script that I have
written.  It pulls the infromation from the database correctly, but is
printing out the html tags in the browser, not sure what is wrong:

Script

#!/usr/bin/python

# import MySQL module
import MySQLdb, cgi

# connect
db = MySQLdb.connect(host="localhost", user="nancy",
passwd="intentions",
db="ardDB")

# create a cursor
cursor = db.cursor()

# execute SQL statement
cursor.execute("SELECT * FROM news where storyDATE < '2005-10-1';")

# get the resultset as a tuple
result = cursor.fetchall()

db.close()

print """ Content-Type: text/html\n\n
          <html>
          <head>

          <title>DB Test</tile>

          </head>

          <body>

          """

# iterate through resultset
for record in result:

    print """<h1>%s</h1>

             <p>%s</p>

             <p>%s<p>

           """ %(record[1],record[2],record[3])




print   """

          </body>

          </html>

          """


Results:


<html>
          <head>

          <title>DB Test</tile>

          </head>

          <body>


<h1>Heading 4</h1>

             <p>Body 4</p>

             <p>2005-09-01<p>


<h1>Heading 5</h1>

             <p>Body 5</p>

             <p>2005-09-10<p>


<h1>Heading 6</h1>

             <p>Body 6</p>

             <p>2005-09-12<p>




          </body>
          
          </html>




More information about the Python-list mailing list