flask dropzone整合到form里面(flask 76)

flask dropzone整合到form里面(flask 76)_第1张图片
image.png

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_IN_FORM=True,
DROPZONE_UPLOAD_ON_CLICK=True,
DROPZONE_UPLOAD_ACTION='handle_upload', # URL or endpoint
DROPZONE_UPLOAD_BTN_ID='submit',
)

dropzone = Dropzone(app)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/upload', methods=['POST'])
def handle_upload():
for key, f in request.files.items():
if key.startswith('file'):
f.save(os.path.join(app.config['UPLOADED_PATH'], f.filename))
return '', 204

@app.route('/form', methods=['POST'])
def handle_form():
title = request.form.get('title')
description = request.form.get('description')
return 'file uploaded and form submit
title: %s
description: %s' % (title, description)

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

index.html





Flask-Dropzone Demo: In Form
{{ dropzone.load_css() }}
{{ dropzone.style('border: 2px dashed #0087F7; margin: 10px 0 10px; min-height: 400px; width: 800px') }}


New Album









{{ dropzone.create() }}


{{ dropzone.load_js() }}
{{ dropzone.config() }}

你可能感兴趣的:(flask dropzone整合到form里面(flask 76))