-2
我用Python寫了一個網頁,如下所示:如何包括在Python Web表單自動完成與MongoDB的
#!/usr/bin/env python
import os, re, sys
from datetime import datetime
from pymongo import Connection
import cgi
class Handler:
def do(self, environ, start_response):
html = "<html><head><title>C Informatics</title></head><body>"
html += "<h1><center>National Management & Information System</h1>"
html += '<center><h3>CONTROL PROGRAMME<br>'
html += '</center>'
html += '<form method="post" action="newreg.py">'
html += 'Person Name :<input type="text" name="pname">'
html += 'Age :<input type="text" name="age">'
html += 'Gender : <input type="radio" name="sex" value="male">M'
html += '<input type="radio" name="sex" value="female">F<br><br>'
html += 'Complete Address :<br>'
html += 'H.No. and Street :<input type="text" name="hn1">'
html += 'Locality : <input type="text" name="locality">'
html += 'PIN Code : <input type="text" name="pin"><br>'
html += '<input type="submit" Value="Save">'
html += '</form>'
html += '</center>'
html += "</body></html>"
connection = Connection('localhost', 27017)
db = connection.health
tc = db.testColl
item = tc.find_one()["name"]
html += str(item)
html += name
output = html
mimeType = "text/html"
在上面的表格,我想自動完成表單字段「位置」(也拉取出該位置的相應PIN碼並顯示在字段PIN中)。
數據,位置名稱及其各自的PIN碼,保存在MongoDB的集合中。
因此,單擊'保存'時,信息將保存在MongoDB中的新集合中。
有了代碼,有人可以告訴我怎麼做嗎?
感謝
NC