【问题标题】:How to include autocomplete in a python web form with MongoDB如何在 MongoDB 的 Python Web 表单中包含自动完成功能
【发布时间】:2011-09-20 04:53:54
【问题描述】:

我用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

【问题讨论】:

    标签: python forms autocomplete


    【解决方案1】:

    这个问题与 Python 和 MongoDB 无关。您正在尝试的是通过 Javascript 实现的一些自动完成功能。

    http://docs.jquery.com/Plugins/autocomplete

    是一个好的开始。

    【讨论】:

      猜你喜欢
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 2011-08-05
      • 2020-04-23
      • 2013-02-08
      • 1970-01-01
      • 2018-02-11
      • 1970-01-01
      相关资源
      最近更新 更多