One - One Code All

Blog Content

Flask如何获取Post传过来的参数?

Python   2013-11-18 22:28:36

Flask如何获取Post传过来的参数?


客户端用json,服务端用 request.data, 

客户端用data, 服务端用 request.form/request.values


用到Request Object,比如

request.form['username']

官方文档有介绍


http://flask.pocoo.org/docs/quickstart/#accessing-request-data

http://flask.pocoo.org/docs/api/#incoming-request-data

http://flask.pocoo.org/docs/api/#flask.request



取得post中返回的data数据的话

1.去values里面去取得


html页面:


$.post($SCRIPT_ROOT + '/update_file/' + file_name,

           { 'newtext': $(".modal-body textarea").val() },

           //{ 'newtext': "abc" },

           function(data,status){

           //  if(status == "success")

           //  window.location.href="{{ url_for('refresh') }}";

  

      }); 

      

      

view.py


value = request.values.get('newtext', 0)

 

2.去form里面去取得


print request.form.get('myid')    #input

print request.form.getlist('mychecks')    #check组




上一篇:python中datetime获取几分钟、小时、天之前的时间
下一篇:pandas.DataFrame选取特定行

The minute you think of giving up, think of the reason why you held on so long.