赞
踩
一段上传和访问的demo
#!/usr/bin/python3 #encoding:utf-8 #来自官网,但官网的不能直接用,稍微修改了一下,秒秒钟运行成功,哈哈哈哈 import os from flask import Flask, request, redirect, url_for from werkzeug.utils import secure_filename from flask import send_from_directory UPLOAD_FOLDER = './inference/images'#上传到这里 ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif','jpeg','rar','doc','docx','dot','pptx','db'])#允许的格式,保证安全性 app = Flask(__name__) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['MAX_CONTENT_LENGTH'] = 64 * 1024 * 1024#限制大小64mb def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS @app.route('/', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': file = request.files['file'] if file and allowed_file(file.filename): #filename = secure_filename(file.filename) filename =request.form['filename']#文件名,支持中文哦!!! filename =str(filename)#防止恶意传送非正常字符导致服务器异常 file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return redirect(url_for('uploaded_file', filename=filename)) return ''' <!doctype html> <title>上传文件</title> <h1>上传文件</h1> <form action="" method=post enctype=multipart/form-data> <p><input type=file name=file></br> <input type="text" name="filename"></p> <input type=submit value="上传"> </form> ''' @app.route('/uploads/<filename>') def uploaded_file(filename): return send_from_directory(app.config['UPLOAD_FOLDER'], filename) if __name__=='__main__': app.run(port=80,debug=True)
我在项目根目录下的flask_server2中指定跳转到predict控制器
并设置上传文件和访问位置
predict模块进行检测
并由showDetectResult展示
(只能上传图片)
我指定模型读取的路径了,所以上传的文件明是有限制的(相当于写死了).
加入mp4就行…
ctrl+f 是pycharm搜索搜索当前文件
f8逐行执行到需要跳转的函数时,
到想要跳转的函数那打一个断点,然后step out
完美。
(也可以直接step out到下一个断点。。)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。