将JSON从jQuery .getJSON传递给Python
我一直在准备远离PHP,并决定将Python用于我的下一个项目,我已经设法让自己完全陷入困境,我想知道是否有人可以帮助我。
如果我执行:
$.getJSON('test.php', { testdata: 'hello world' })
在’test.php’我可以使用
$_GET['testdata']
检索’你好世界’。
我似乎找不到test.py的等价物:
$.getJSON('test.py', { testdata: 'hello world' })
我已经看到在线发布的与request.get或os.environment有关的代码来获取数据,但我没有做任何配置工作。 有人会有什么建议吗?
我对开发很陌生,如果我错过了一些明显的东西,那么道歉。
好的谢谢
这对我有用:
import cgi import cgitb #this... cgitb.enable() #..and this are not really necessary but helps debuging data= cgi.FieldStorage() #remove this commant to take a look in the data received by python #print data #here you can retrieve the value passed by ajax print data['testdata'].value
我希望这个对你有用。
cgi
文档包含有关如何在Python CGI脚本中检索GET和POST变量的信息。