Image Upload Preview
Multi-image upload with thumbnail preview.
Preview
Usage
views.py
python
from djust import LiveView
from djust.components import ImageUploadPreview
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = ImageUploadPreview()my_template.html
django
{{ component }}Needs its script on the page: <script src="{% static 'djust_components/image-upload-preview.js' %}"></script>. djust ships it; without it the markup renders but does not update in the browser.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name | str | 'images' | Form field name. |
| max | int | 5 | Maximum number of images (selected plus ``previews``). |
| event | str | None — renames the event | None | Event fired when a selection has uploaded (see above). Nothing is sent unless you name one. |
| accept | str | 'image/*' | Accepted MIME types (default: image/*). |
| previews | list | None | None | List of existing preview URLs. |
| custom_class | str | '' | Additional CSS classes. |
| upload | str | None | None | Upload slot name (``allow_upload``); ``None`` is a plain input. |
| max_size | int | 0 | Largest file in bytes to pre-check (``0``: no pre-check). |
| **kwargs | — passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state | — | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.image_upload_preview | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 8 of this component's classes at line 2400, 2401, 2403, 2404, 2405, 2408, 2409, 2423. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |