簡體   English   中英

Python Mongo DB mod_wsgi表單操作插入

[英]Python Mongo DB mod_wsgi form action 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中沒有插入事件。

請幫忙 !!!

謝謝

也許嘗試完全重啟Apache。 錯誤消息與您提供的代碼段不匹配。

更改代碼后,需要重新啟動進程,因為不會自動檢測到它們。 讀:

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

建議您在進行任何更改以觸發進程重啟之后,使用守護程序模式並觸摸WSGI腳本文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM