0

私は PHP から離れる可能性に備えており、次のプロジェクトで Python を使用することに決めました。何かに完全に行き詰まってしまったので、誰か助けてもらえないだろうかと考えています。

私が実行する場合:

$.getJSON('test.php', { testdata: 'hello world' })

「test.php」で使用できます

$_GET['testdata']

「Hello World」を取得します。

test.py に相当するものが見つからないようです:

$.getJSON('test.py', { testdata: 'hello world' })

データを取得するために request.get または os.environment に関連してオンラインで投稿されたコードを見たことがありますが、構成を機能させることができませんでした。誰か提案はありますか?

私は開発にかなり慣れていないので、明らかな何かを見逃している場合は申し訳ありません。

よろしくお願いします

4

2 に答える 2

2

これは私にはうまくいきます:

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

うまくいくことを願っています。

于 2012-04-19T16:28:22.223 に答える
0

cgiドキュメントには、Python CGI スクリプトで GET および POST 変数を取得する方法に関する情報が含まれています。

于 2012-04-19T16:28:43.547 に答える