Wed Development - Dynamically Generated News Index

Steve Holden steve at holdenweb.com
Tue Dec 20 16:51:21 EST 2005


infidel02 at lycos.com wrote:
> 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

Your problem is that space before the HTTP header. Get rid of that and 
you'll probably find that the browser recognises your output as HTML. Try

print """Content-Type: text/html\r\n\r\n ...

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list