Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get Mini Program Request data in Flask

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "how to get Mini Program Request data in Flask", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to get Mini Program Request data in Flask" article.

Two methods of obtaining Mini Program Request data in Flask

As back-end dicks are really secretive about the front end, the type Object in JS can not be directly passed into the background Flask through POST. You will find that what you get is [object Object], which is just a Str in Flask, .

So, start looking for a solution:

First, transfer parameters through GET or POST, and convert Object to Str request data:

1. Define a JS function in util.js:

Function json2Form (json) {var str = []; for (var p in json) {str.push (encodeURIComponent (p) + "=" + encodeURIComponent (json [p]));} return str.join ("&");} module.exports = {json2Form: json2Form,}

two。 Load the function on the appropriate page and call it:

Var Util = require ('.. / utils/util.js') wx.request ({url: App.Config.post_Data,// 's own service interface address method: 'POST', header: {' content-type': 'application/x-www-form-urlencoded'}, data: {postdata:Util.json2Form (params)}, / / pay attention to this! Success: function (data) {console.log ('data has been submitted to database')})

Of course, you can also use your URl+Util.json2Form (params) here, and then use GET to request.

3.Flask backend acquires data:

Postdata = request.values.get ('postdata')

Second, convert Object to Json () format by passing parameters through POST:

1. Mini Program directly converts the request data into Json format:

Wx.request ({url: App.Config.post_Data, method: 'POST', header: {' content-type': 'application/x-www-form-urlencoded'}, data: {postdata: JSON.stringify (params)}, / / pay attention to this! Success: function (data) {console.log ('data has been submitted to database')})

2.Flask background processing:

Postdata= request.values.get ('postdata') print (json.loads (postdata)) # pay attention here, ha (postdata) # notice here, change back to DICT format, cordial ing above is about "how to obtain Mini Program Request data in Flask", I believe everyone has a certain understanding, I hope the content shared by the editor will be helpful to you, if you want to know more related knowledge content Please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report