.cgi problem with web server

后端 未结 4 1580
粉色の甜心
粉色の甜心 2021-01-27 03:07

The code

#!/usr/bin/env python

import MySQLdb

print \"Content-Type: text/html\"
print 
print \"Books         


        
4条回答
  •  死守一世寂寞
    2021-01-27 03:36

    I've tidied up the code a bit by inserting linebreaks where necessary and replacing smart quotes with " and '. Do you have any more luck with the following? Can you run it from a terminal just by typing python test.cgi?

    #!/usr/bin/env python
    
    import MySQLdb
    
    print "Content-Type: text/html"
    print
    print "Books"
    print ""
    print "

    Books

    " print "
      " connection = MySQLdb.connect(user='me', passwd='letmein', db='my_db') cursor = connection.cursor() cursor.execute("SELECT name FROM books ORDER BY pub_date DESC LIMIT 10") for row in cursor.fetchall(): print "
    • %s
    • " % row[0] print "
    " print "" connection.close()

提交回复
热议问题