当前位置: 代码迷 >> SQL >> Django-1.3的helloworld4 写sql话语
  详细解决方案

Django-1.3的helloworld4 写sql话语

热度:11   发布时间:2016-05-05 12:46:36.0
Django-1.3的helloworld4 写sql语句
这段代码让人怀念刚学jdbc的时候
#!/usr/bin/pythonimport MySQLdbprint "Content-Type: text/html"printprint "<html><head><title>Books</title></head>"print "<body>"print "<h1>Books</h1>"print "<ul>"connection = MySQLdb.connect(user='root', passwd='haoning', db='test')cursor = connection.cursor()cursor.execute("select question from polls_poll ORDER BY pub_date DESC LIMIT 10")for row in cursor.fetchall():    print "<li>%s</li>" % row[0]print "</ul>"print "</body></html>"connection.close()