python flask实战订餐系统微信小程序-43初始化上次圖片的配置
2021/8/24 20:06:38
本文主要是介绍python flask实战订餐系统微信小程序-43初始化上次圖片的配置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
B站配套视频教程观看
初始化上次圖片的配置
基于user/index.py定义Upload.py接口
# -*- coding: utf-8 -*- from flask import Blueprint,request,jsonify from application import app import re,json route_upload = Blueprint( 'upload_page',__name__ ) @route_upload.route("/ueditor",methods = [ "GET","POST" ]) def ueditor(): req = request.values action = req['action'] if 'action' in req else '' if action == "config": root_path = app.root_path config_path = "{0}/web/static/plugins/ueditor/upload_config.json".format( root_path ) with open( config_path,encoding="utf-8" ) as fp: try: config_data = json.loads( re.sub( r'\/\*.*\*/' ,'',fp.read() ) ) except: config_data = {} return jsonify( config_data ) if action == "uploadimage": return uploadImage() return "upload" def uploadImage(): resp = { 'state':'SUCCESS','url':'','title':'','original':'' } return jsonify( resp )
添加www.py引入
# -*- coding: utf-8 -*- from application import app ''' 统一拦截处理和统一错误处理 ''' from web.interceptors.AuthInterceptor import * from web.interceptors.ApiAuthInterceptor import * from web.interceptors.ErrorInterceptor import * ''' 蓝图功能,对所有的url进行蓝图功能配置 ''' from web.controllers.index import route_index from web.controllers.user.User import route_user from web.controllers.static import route_static from web.controllers.food.Food import route_food from web.controllers.account.Account import route_account from web.controllers.member.Member import route_member from web.controllers.finance.Finance import route_finance from web.controllers.stat.Stat import route_stat from web.controllers.api import route_api from web.controllers.upload.Upload import route_upload from web.controllers.chart import route_chart app.register_blueprint( route_index,url_prefix = "/" ) app.register_blueprint( route_user,url_prefix = "/user" ) app.register_blueprint( route_static,url_prefix = "/static" ) app.register_blueprint( route_account,url_prefix = "/account" ) app.register_blueprint( route_food,url_prefix = "/food" ) app.register_blueprint( route_member,url_prefix = "/member" ) app.register_blueprint( route_finance,url_prefix = "/finance" ) app.register_blueprint( route_stat,url_prefix = "/stat" ) app.register_blueprint( route_api,url_prefix = "/api" ) app.register_blueprint( route_upload,url_prefix = "/upload" ) app.register_blueprint( route_chart,url_prefix = "/chart" )
运行可以看到成功上传
统一封装上传图片的方法:
# -*- coding: utf-8 -*- class UploadService(): @staticmethod def uploadByFile( file ): resp = { 'code':200,'msg':'操作成功~~','data':{} } return resp
引入上傳服務
from common.libs.UploadService import UploadService def uploadImage(): resp = { 'state':'SUCCESS','url':'','title':'','original':'' } ret = UploadService.uploadByFile( upfile ) return jsonify( resp )
这篇关于python flask实战订餐系统微信小程序-43初始化上次圖片的配置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享
- 2024-12-19使用python 把docx转为pdf文件有哪些方法?-icode9专业技术文章分享
- 2024-12-19python怎么更换换pip的源镜像?-icode9专业技术文章分享