1、微信小程序端:

(1)index.js

//index.js
//获取应用实例
const app = getApp()Page({data: {motto: '检测结果:',value: '0',userInfo: {},hasUserInfo: false,canIUse: wx.canIUse('button.open-type.getUserInfo'),userImage: "/images/jia.png",img_arr: [],},//事件处理函数bindViewTap: function() {var that = this //!!!!!!!!!“搭桥”//利用API从本地读取一张图片wx.chooseImage({count: 1,sizeType: ['original', 'compressed'],sourceType: ['album', 'camera'],success: function (res) {var tempFilePaths = res.tempFilePaths//将读取的图片替换之前的图片that.setData({ userImage: tempFilePaths[0],img_arr: that.data.img_arr.concat(tempFilePaths[0]),})//通过that访问console.log(that.data.userImage)}})},changeName: function (e) {this.setData({value: "xiao",})},upload: function () {var that = thiswx.uploadFile({url: 'http://127.0.0.1:8090/postdata',// filePath: that.data.img_arr[0],filePath: that.data.userImage,name: 'content',// formData: adds,success: function (res) {console.log(res.data);that.setData({value: JSON.parse(res.data)['value'],userImage: JSON.parse(res.data)['resurl']})if (res) {wx.showToast({title: '检测完成!',duration: 3000});}}})this.setData({formdata: ''})}, takePhoto() {var that = thiswx.chooseImage({count: 1, // 默认9sizeType: ['original', 'compressed'],sourceType: ['camera'],success: function (res) {var tempFilePaths = res.tempFilePathsthat.setData({userImage: res.tempFilePaths[0],})console.log("res.tempImagePath" + tempFilePaths[0])}})},onLoad: function () {if (app.globalData.userInfo) {this.setData({userInfo: app.globalData.userInfo,hasUserInfo: true})} else if (this.data.canIUse){// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回// 所以此处加入 callback 以防止这种情况app.userInfoReadyCallback = res => {this.setData({userInfo: res.userInfo,hasUserInfo: true})}} else {// 在没有 open-type=getUserInfo 版本的兼容处理wx.getUserInfo({success: res => {app.globalData.userInfo = res.userInfothis.setData({userInfo: res.userInfo,hasUserInfo: true})}})}},getUserInfo: function(e) {console.log(e)app.globalData.userInfo = e.detail.userInfothis.setData({userInfo: e.detail.userInfo,hasUserInfo: true})}})

(2)index.wxml

<!--index.wxml-->
<view class="container"><view class='imagesize'><image src='{{userImage}}'></image></view><view class="usermotto"><text>{{motto}}</text><text>{{value}}</text></view><view class='userbtn'><button bindtap='bindViewTap'>选择图像</button><button bindtap="takePhoto">相机拍照</button><button bindtap="upload"> 开始检测 </button></view>
</view>

(3)index.wxss

/**index.wxss**/
.imagesize{display:flex;width:100%;height: 800rpx;justify-content: center;
}
.imagesize image { width:90%;height: 800rpx;
}.usermotto {width:100%;height: 50rpx;text-align: left;margin-top: 100px;
}
.userbtn
{display:flex;width: 92%;margin-top: 20rpx;justify-content: center;
}
.userbtn button
{background-color: #ff8719;color: white;border-radius: 25rpx;
}

2、Python Flask端

from flask import  Flask
from flask import request
import json
import os
import uuid
import cv2app = Flask(__name__)@app.route("/")
def index():return "Hello"resSets = {}
@app.route('/postdata', methods=['POST'])
def postdata():f = request.files['content']user_input = request.form.get("name")basepath = os.path.dirname(__file__)  # 当前文件所在路径src_imgname = str(uuid.uuid1()) + ".jpg"upload_path = os.path.join(basepath, 'static/srcImg/')if os.path.exists(upload_path)==False:os.makedirs(upload_path)f.save(upload_path + src_imgname)im = cv2.imread(upload_path + src_imgname, 0)save_path = os.path.join(basepath, 'static/resImg/')if os.path.exists(save_path) == False:os.makedirs(save_path)save_imgname = str(uuid.uuid1()) + ".jpg"cv2.imwrite(save_path + save_imgname, im)resSets["value"] = 10resSets["resurl"] = "http://127.0.0.1:8090" +'/static/resImg/' + save_imgnamereturn json.dumps(resSets, ensure_ascii=False)if __name__=="__main__":app.run(host="0.0.0.0", port=8090)

3、结果

微信小程序post请求Python Flask数据相关推荐

  1. python搭建微信小程序百度云_微信小程序-订餐系统-Python flask构建

    总大小:14.3 GB └-python3+flask └-centos ├-CentOS-7-x86_64-Minimal-1804.iso 906.0 MB └-mysql ├-mysql-ins ...

  2. 微信小程序request请求动态获取数据

    微信小程序开发文档链接 1 后台代码: clickButton:function(){var that = this;wx.request({url: 'http://localhost:9096/a ...

  3. 微信小程序 解决请求服务器手机预览请求不到数据的方法

    微信小程序 解决请求服务器手机预览请求不到数据的方法 微信小程序的文档中明确说明了所有的请求是必须使用https的,以没用过https,由于小程序,不得不接触到https,研究了好长时间把tomcat ...

  4. 微信小程序如何请求数据

    微信小程序呢不存在ajax,那么它是如何实现数据请求功能的呢? 在微信官方文档中提供了API的调用wx.request()来请求数据 在数据请求之前,我们需要把微信小程序数据请求的坑过一遍 1:微信小 ...

  5. mpvue微信小程序http请求-fly.js

    mpvue微信小程序http请求-fly.js fly.js是什么? 一个支持所有JavaScript运行环境的基于Promise的.支持请求转发.强大的http请求库.可以让您在多个端上尽可能大限度 ...

  6. 微信小程序request请求封装;微信小程序封装request请求;uni-app小程序封装request请求;

    本片封装了微信小程序request请求:为别是post get put请求,重点在request.js文件 1.新增四个文件 2.根目录下的utils下的request.js封装uni.request ...

  7. python语言小程序-微信小程序可以用Python语言编写吗?

    Q: 微信小程序可以用Python语言编写吗? A: 小程序一般开发HTML.CSS.JS,需要后台开发就需要PHP,MySQL等了.你说的这种语言开发小程序不好使.如果你不想学更多,建议你找一家专业 ...

  8. 微信小程序使用echarts实时更新数据以及常见bug

    ** 微信小程序使用echarts实时更新数据以及常见bug ** 参考echarts官方文档:https://echarts.apache.org/zh/tutorial.html 下载小程序ech ...

  9. 微信小程序request请求后台接收不到参数问题

    微信小程序request请求后台接收不到参数问题 一. 小程序部分代码 二. 后端 三. 问题代码 四. 请求头 一. 小程序部分代码 发一个普通的request请求 wx.request({url: ...

最新文章

  1. mysql多索引结构_MySQL 索引结构
  2. MSSQL - 因为数据库正在使用,所以无法获得对数据库的独占访问权。
  3. ASP.NET MVC学习资料 新增几个开源项目
  4. OkHttp实现文件上传进度
  5. idea编辑springboot,如何打成war包
  6. centos 7 关闭 firewall、iptables
  7. 疯了,要建飞铁!比飞机快3倍,4000km/h,北京到深圳半小时
  8. docker容器内没有yum命令_为什么不建议把数据库部署在Docker容器内?
  9. Java 8 的这个新特性,用起来真的很爽!
  10. 开源人脸识别项目 —— face_recognition
  11. 阿里应该如何整合高德
  12. python中的抽象类
  13. 520快到了,给你对象写个怦然心动吧
  14. Topaz DeNoise AI for Mac(AI智能图像降噪工具)
  15. ROsalind 014 Finding a Shared Motif
  16. 彩色激光同轴位移计在点胶行业的应用(胶水测量)
  17. Ctrix卸载ReceiverCleanupUtility.exe
  18. Ansible——Ansible的练习
  19. 【lintcode】树形数据结构之Maxtree, Tree iterator, remove bst node, 优先队列之动态中位数Median, 矩阵dfs之word search II,最大连
  20. 今天14:00 | NeurIPS 专场八

热门文章

  1. u盘装linux minimal,CentOS 7 Minimal 镜像U盘引导
  2. minimal linux图形化,CentOS7 Minimal 最小化安装后再安装GNOME图形界面
  3. easyuefi linux win8,EasyUEFI(启动项管理软件)
  4. base64图片的优缺点(雪碧图)
  5. python endif_python – Django:无效的块标记:’static’,预期’endif’
  6. 工业应用中如何选取合适的损失函数(MAE、MSE、Huber)-Pytorch版
  7. COMSOL 模态分析 (长方体为例)
  8. python处理wrf气象数据_Python气象数据处理与绘图(11):矢量箭头图(风场,通量场)...
  9. Android:三星指纹解锁SDK
  10. mysql 5.5.9_CentOS5.5下安装Mysql 5.5.9GA(或Mysql 5.5.8GA)的经过和心得(笔记)