如何使用 MongoDB 在 python Web 表单中包含自动完成功能
我用 Python 编写了一个网页,如下所示:
#!/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
I wrote a web page in Python as follows:
#!/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"
In the above form, I want to autocomplete the form field 'Location' (which also pulls out the respective PIN code of that location and displays in the field PIN).
The Data, Locations Name and their respective PIN code, are saved in a collection in MongoDB.
So that when 'Save' is clicked the information is saved in new collections in MongoDB.
With code, can some one please show me how it can be done ?
Thanks
NC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题与Python和MongoDB无关。您正在尝试的是通过 Javascript 实现一些自动完成功能。
http://docs.jquery.com/Plugins/autocomplete
是一个好的开始。
This question has neither to do with Python nor with MongoDB. What you are trying is some auto-complete functionality through Javascript.
http://docs.jquery.com/Plugins/autocomplete
is a good start.