11.1 python之webpy獲取請求引數,把資料庫結果放到List,Retrofit Post
阿新 • • 發佈:2019-01-28
準備工具類:
def getInput(input):
return htmlquote(dict(input))
def htmlquote(inputData):
if isinstance(inputData,dict) == False:
return web.net.htmlquote(inputData)
else:
for k,v in inputData.items():
inputData[k] = htmlquote(v)
return inputData
使用方法:
class index ():
def index(self):
input = util.getInput(web.input())
print input['name']
return 'hello'
把資料庫查詢結果轉成list:
list = db.select('
test_name', where='id>1000' ,limit='100',order = 'id desc', vars=locals())
def dbList2Json(list):
ret = []
for k,v in enumerate(list):
obj = {}
for k1,v1 in enumerate(v):
obj[v1]=v[v1]
ret.append(obj)
return ret
Retrofit Post
以下兩個方法請求的資料是相同的:
會把中文編碼
@FormUrlEncoded
@POST("/json.php")
void post(
@FieldMap Map<String, String> params,
Callback<Response> callback
);
傳輸二進位制
// @Multipart
//@POST("/json.php")
//void post(@PartMap Map<String, String> params, Callback<Response> callback);