Image Upload Preview

Multi-image upload with thumbnail preview.

python 7 params

Preview

Usage

views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import ImageUploadPreview


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = ImageUploadPreview()

    @event_handler()
    def upload(self, value=None, **kwargs):
        ...  # write to self.component; the re-render carries it
my_template.html
django
{{ component }}

Events this component sends to the view: upload.

Needs a client hook djust does not ship: dj-hook="ImageUploadPreview". The markup renders, but the interaction described above is yours to add — register window.djust.hooks.ImageUploadPreview = { mounted() { … } } before client.js loads (see the hooks guide).

Parameters

NameTypeDefault
namestr'images'
maxint5
eventstr — renames the event'upload'
acceptstr'image/*'
previewslist | NoneNone
custom_classstr''
**kwargs— passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state
Source & styles
FilePathNotes
moduledjust.components.components.image_upload_previewSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 6 of this component's classes at line 2315, 2316, 2318, 2319, 2320, 2321. Override those rules, or the custom properties they read, in a stylesheet loaded after it.