[英]Passing JSON from jQuery .getJSON to 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变量的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.