尝试创建一个web应用程序(使用mySQL和Python),其中包含MA中的徒步旅行路线列表。我只想在一个页面上显示数据库中所有轨迹的名称,但不明白为什么什么都不显示:
################################################################################
def getAllHikes():
"""
This is a middleware function to read from the database.
It returns a list containing records of all trails we have in the table.
"""
# connect to db
conn, cursor = getConnectionAndCursor()
# prepare SQL
sql = """
SELECT name
FROM hiking
"""
# run the SQL
cursor.execute(sql)
# fetch the results
data = cursor.fetchall()
# clean up
cursor.close()
conn.close()
return data
################################################################################
def showAllHikes(data):
'''Produce a table showing all trails, one per row.'''
print('''
Here are all the popular trails we have on file:
<table>
<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>
''') % (name, town)
print('''
</table>
''')
################################################################################
if __name__ == "__main__":
# get form field data
form = cgi.FieldStorage()
doHTMLHead("MassHike: A database of popular Massachusetts trails")
data = getAllHikes()
showAllHikes(data)
doHTMLTail()
当我尝试使用web应用程序时,总是遇到这个问题。我得到一个错误,说args=(“未定义全局名称'name',)
如果你能用非常简单的话来解释,我将不胜感激。我一点也不明白。谢谢!
目前没有回答
相关问题 更多 >
编程相关推荐