【发布时间】:2016-09-30 06:43:59
【问题描述】:
我想在以下 index.html 页面的 <td> 中显示数据库中的每一行:
$def with(items)
<h1></h1>
<br/>
<br>
<table border="1">
<tr>
<th>Name</th>
<th>address</th>
<th>number</th>
</tr>
<tr>
<td>//want name here</td>
<td>//address here</td>
<td>//number here</td>
</tr>
</table>
app.py 代码:
import web
import MySQLdb
urls = (
'/', 'Index'
)
app = web.application(urls, globals())
render = web.template.render('templates/')
class Index(object):
def GET(self):
return render.hello_form()
def POST(self):
form = web.input(name="a", newname="s", number="d")
conn = MySQLdb.connect(host= "localhost", user="root", passwd="", db="testdb")
x = conn.cursor()
x.execute("SELECT * FROM details WHERE name = '%s'" % (form.name))
conn.commit()
items = x.fetchall()
for row in items:
conn.rollback()
conn.close()
return render.index(items)
if __name__ == "__main__":
app.run()
【问题讨论】:
-
我在这里看到的是 SQL 注入吗?
-
我没听懂你..?@aif
-
如果 name =
' union select concat(login, ':', password) from users where user='admin会发生什么? (是的,那是伪代码)见owasp.org/index.php/SQL_Injection
标签: python python-2.7 web.py