python 使用Flask-Uploads进行照片上传演示。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用Flask-Uploads进行照片上传演示。相关的知识,希望对你有一定的参考价值。
# -*- coding: utf-8 -*-
import os
from flask import Flask, request
from flask_uploads import UploadSet, configure_uploads, IMAGES, patch_request_class
app = Flask(__name__)
app.config['UPLOADED_PHOTOS_DEST'] = os.getcwd()
photos = UploadSet('photos', IMAGES)
configure_uploads(app, photos)
patch_request_class(app) # set maximum file size, default is 16MB
html = '''
<!DOCTYPE html>
<title>Upload File</title>
<h1>Photo Upload</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=photo>
<input type=submit value=Upload>
</form>
'''
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST' and 'photo' in request.files:
filename = photos.save(request.files['photo'])
file_url = photos.url(filename)
return html + '<br><img src=' + file_url + '>'
return html
if __name__ == '__main__':
app.run()
以上是关于python 使用Flask-Uploads进行照片上传演示。的主要内容,如果未能解决你的问题,请参考以下文章
flask-uploads扩展的使用笔记
Flask入门文件上传flask-uploads
毕业了,在Python中使用 OpenCV 和K-Means 聚类对毕业照进行图像分割
毕业了,在Python中使用 OpenCV 和K-Means 聚类对毕业照进行图像分割
python图像识别---------图片相似度计算
教你用OpenCV 和 Python给证件照换底色(蓝底 <-;红底-;白底)