How to include autocomplete in a python web form with MongoDB
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
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.
精彩评论