+ -
当前位置:首页 → 问答吧 → (求助)python3 web 传递参数 返回 数据库 查询结果

(求助)python3 web 传递参数 返回 数据库 查询结果

时间:2010-12-19

来源:互联网

[i=s] 本帖最后由 Chrome 于 2010-12-19 22:42 编辑 [/i]

我是新手!

我的运行环境 python3.12  win xp SP3 iis5+.py

我的想法: 通过 input.html  输入一些数字,传递到 result.py 中,result.py把输入的数字在数据库中查询出来,反馈到页面上。



=========input.thml============= code:

<html>
Please input the number:
<p>
<div class="top w960 center">
<form action="result.py" method="post">
number: <input type="text" name="txtWords"><br>
<input type="submit">
</div>
</form>
</html>

==========result.py============code:
#coding=utf-8
import cx_Oracle,os,sys,http.client,urllib.parse,urllib.request
words=request.post['txtWords']
conn = cx_Oracle.connect('wahaha','123456','18.97.27.6:1521/chrome')  
cursor = conn.cursor()
sql = "select staff_number,cash,key_status,valid_time from staff_info where staff_number ='"+words+"'"
cursor.execute(sql)
for r in cursor.fetchall():print ("number: %s  cash: %s  status: %s  valid: %s " % (r[0], r[1],r[2],r[3]))

===========================================
[color=Blue]代码执行以后,每次都是返回

Traceback (most recent call last):
  File "D:\Soft\Python31\web\result.py", line 3, in
    words=request.post['txtWords']
NameError: name 'request' is not defined[/color]

作者: Chrome   发布时间: 2010-12-19

我想自己写,暂时不想用其他的页面模版。

谢谢各位路过的,如果有遇到过这类问题,请推荐一本书或文章给我看也行。谢谢!

作者: Chrome   发布时间: 2010-12-19