$_POST
PHP では、POST とGET (クエリ文字列) 変数を使用できます$_GET
。Python で同等のものは何ですか?
ベストアンサー1
次のような HTML フォームを投稿するとします。
<input type="text" name="username">
使用する場合生のCGI:
import cgi
form = cgi.FieldStorage()
print form["username"]
print request.GET['username'] # for GET form method
print request.POST['username'] # for POST form method
from cherrypy import request
print request.params['username']
ウェブ:
form = web.input()
print form.username
工具:
print request.form['username']
Cherrypy または Turbogears を使用する場合は、パラメータを直接受け取るハンドラー関数を定義することもできます。
def index(self, username):
print username
class SomeHandler(webapp2.RequestHandler):
def post(self):
name = self.request.get('username') # this will get the value from the field named username
self.response.write(name) # this will write on the document
したがって、実際にはこれらのフレームワークのいずれかを選択する必要があります。