在应用引擎上序列化表单提交的值

ofk*_*fko 0 python google-app-engine json

我只想序列化提交表单的所有字段,如PHP中所示:

json_encode($_GET)
Run Code Online (Sandbox Code Playgroud)

json.dumps(self.request.get) 不起作用:

<type 'exceptions.TypeError'>: <bound method Request.get of <Request at 77ea190 GET http://localhost:8083/?a=value>> is not JSON serializable 
      args = ('<bound method Request.get of <Request at 77ea190...ocalhost:8083/?a=value>> is not JSON serializable',) 
      message = '<bound method Request.get of <Request at 77ea190...ocalhost:8083/?a=value>> is not JSON serializable'
Run Code Online (Sandbox Code Playgroud)

我已经尝试过使用CGI模块,这也给出了一个不可序列化的错误.我想你想知道:我使用它将数据发送回我的模板以重新填充表单字段.

cha*_*lax 5

self.request.get返回get方法,而不是方法返回的方法.你必须这样做:

json.dumps(self.request.GET.items())
Run Code Online (Sandbox Code Playgroud)

request.GET将返回一个UnicodeMultiDict对象,并request.GET.items()返回一个元组列表,每个元组都是(key, value).

参看 http://code.google.com/appengine/docs/python/tools/webapp/requestclass.htmlhttp://docs.webob.org/en/latest/reference.html#id1