1. 程式人生 > >python與web進行互動

python與web進行互動

我的想法: 通過 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]