[英]Mod_python not getting GET variables
I have standard 13.10 Ubuntu. 我有标准的13.10 Ubuntu。 Running Apache 2 and mod_python.
运行Apache 2和mod_python。 Both installed using apt-get.
两者都使用apt-get安装。 I'm trying to pass a GET variable from the client to the server, execute python script and then return a result.
我正在尝试将GET变量从客户端传递到服务器,执行python脚本,然后返回结果。
Here is my ApacheConfig (Default plus code below): 这是我的ApacheConfig(默认加上下面的代码):
ScriptAlias /tm/ "/home/tm/"
<Directory /home/tm/ >
Require all granted
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
Python Code: test.py Python代码:test.py
import csv
def index():
form = cgi.FieldStorage()
return form
I tried http://myWebsite.com/tm/test.py?testVariable=This 我尝试了http://myWebsite.com/tm/test.py?testVariable=This
returns: FieldStorage(None, None, []) - Meaning the GET variables are not being passed over. 返回: FieldStorage(None,None,[]) -表示未传递GET变量。
As others have said in comment, you should try to use anything other than mod_python. 正如其他人在评论中说的那样,您应该尝试使用除mod_python之外的任何其他内容。 Flask is an excellent python microframerwork http://flask.pocoo.org/
Flask是出色的python microframerwork, 网址为http://flask.pocoo.org/
Assuming you are for some reason locked to mod_python: You need to read the input variable, you are instead creating a new blank instance and returning that. 假设由于某种原因您被锁定在mod_python上:您需要读取输入变量,而是创建一个新的空白实例并将其返回。
def index():
form = cgi.FieldStorage() #this is creating a new/blank instance
return form
you want to read the global copy in the "req" variable: 您想在“ req”变量中读取全局副本:
def index():
return req.form
Again, if you have a choice, please do everything you can to avoid using mod_python. 同样,如果可以选择,请尽一切可能避免使用mod_python。 It was good in its day, but shouldn't be your go to python web framework.
当时很好,但不应该成为python Web框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.