11.1 python之webpy获取请求参数,把数据库结果放到List,Retrofit Post

准备工具类:

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);

更多注解高级用法:
http://www.bkjia.com/Androidjc/995850.html

你可能感兴趣的:(python)