Python Mongo DB mod_wsgi表单动作插入

时间:2011-08-30 09:43:39

标签: python forms list mongodb insert

我有一个newreg.py生成的网页,当我点击保存/提交按钮时,用insertNew.py写的动作来读取数据并插入MongoDB。

在newreg.py中

     html += '<form method=post action="insertNew.py">'

 state = form.getvalue('state','<font color="#FF0000">ERROR</font>')
 district = form.getvalue('district','<font color="#FF0000">ERROR</font>')
     dcode = form.getvalue('Dcode','<font color="#FF0000">ERROR</font>')

”      html + ='

在insertNew.py

 connection = Connection('localhost', 27017)
 db = connection.health
 tc = db.tb_treat_card
     newPatient = str(state)     
     tc.insert()[newPatient]
     html += newPatient
     output = html
     mimeType = "text/html"

     status = "200 OK"
     response_headers = [("Content-type", mimeType),
        ("Content-length", str(len(output)))]

     start_response(status, response_headers)
     return [output]

以下是来自apache日志的错误

[Tue Aug 30 14:12:20 2011] [error] [client 192.168.1.9] Traceback (most recent call last):
[Tue Aug 30 14:12:20 2011] [error] [client 192.168.1.9]   File "/home/dev/wsgi-scripts/newreg.py", line 178, in application 
[Tue Aug 30 14:12:20 2011] [error] [client 192.168.1.9]     return handler.do(environ, start_response)
[Tue Aug 30 14:12:20 2011] [error] [client 192.168.1.9]   File "/home/dev/wsgi-scripts/newreg.py", line 156, in do
[Tue Aug 30 14:12:20 2011] [error] [client 192.168.1.9]     html += str(newPatient)
[Tue Aug 30 14:12:20 2011] [error] [client 192.168.1.9] NameError: global name 'newPatient' is not defined
[Tue Aug 30 14:12:20 2011] [error] [client 192.168.1.9] File does not exist: /home/dev/wsgi-scripts/favicon.ico

并且屏幕不显示任何错误,只需刷新网页即可。此外,MongoDB中没有发生插入。

请帮助!!!

由于

1 个答案:

答案 0 :(得分:0)

也许尝试完整的Apache重启。错误消息与您提供的代码段不匹配。

代码更改后需要重新启动进程,因为它们不会自动检测到。读:

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

建议您使用守护程序模式并在进行任何更改后触摸WSGI脚本文件以触发进程重新启动。