flask dropzone上传之后跳转(flask 72)

app.py

import os

from flask import Flask, render_template, request from flask_dropzone import Dropzone

basedir = os.path.abspath(os.path.dirname(file))

app = Flask(name)

app.config.update( UPLOADED_PATH=os.path.join(basedir, 'uploads'), # Flask-Dropzone config: DROPZONE_ALLOWED_FILE_TYPE='image', DROPZONE_MAX_FILE_SIZE=3, DROPZONE_MAX_FILES=30, DROPZONE_REDIRECT_VIEW='completed' # set redirect view )

dropzone = Dropzone(app)

@app.route('/', methods=['POST', 'GET']) def upload(): if request.method == 'POST': f = request.files.get('file') f.save(os.path.join(app.config['UPLOADED_PATH'], f.filename)) return render_template('index.html')

@app.route('/completed') def completed(): return '<h1>The Redirected Page</h1><p>Upload completed.</p>'

if name == 'main': app.run(debug=True)

index.py

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Flask-Dropzone Demo: Basic</title> {{ dropzone.load_css() }} {{ dropzone.style('border: 2px dashed #0087F7; margin: 10%; min-height: 400px;') }} </head> <body> {{ dropzone.create(action='upload') }} {{ dropzone.load_js() }} {{ dropzone.config() }} </body> </html>

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券