Basic Usage
=============
Installation
------------
.. code-block:: bash
$ pip install flask-dropzone
Initialization
---------------
Initialize the extension:
.. code-block:: python
from flask_dropzone import Dropzone
app = Flask(__name__)
dropzone = Dropzone(app)
This extension also supports the `Flask application factory
pattern
Remember to edit the ``action`` to the URL or endpoint which handles the uploads, for example ``dropzone.create(action='upload_view')`` or ``dropzone.create(action=url_for('upload_view')')``. The default ID of the dropzone form element is `myDropzone`, usually you don't need to change it. If you have specific need, for example, you want to have multiple dropzones on one page, you can use the ``id`` parameter to assign the id: .. code-block:: jinja {{ dropzone.create(id='foo') }} {{ dropzone.create(id='bar') }} ... {{ dropzone.config(id='foo') }} {{ dropzone.config(id='bar') }} Notice that the same id must passed both in ``dropzone.create()`` and ``dropzone.config()``. Beautify Dropzone ----------------- Style it according to your preferences through ``dropzone.style()`` method: .. code-block:: jinja
{{ dropzone.load_css() }} {{ dropzone.style('border: 2px dashed #0087F7; margin: 10%; min-height: 400px;') }} Save Uploads with Flask ----------------------- When the file was dropped on drop zone, you can get the uploaded file in ``request.files``, just pass upload input's name attribute (default to ``file``). .. code-block:: python import os from flask import Flask, request from flask_dropzone import Dropzone app = Flask(__name__) dropzone = Dropzone(app) @app.route('/uploads', methods=['GET', 'POST']) def upload(): if request.method == 'POST': f = request.files.get('file') f.save(os.path.join('the/path/to/save', f.filename)) return 'upload template' .. tip:: See ``examples/basic`` for more detail.