django-filepond-form-widget
A Django form widget using FilePond with image preview support.
Table of Contents
Features
- Easy Integration: Seamlessly integrates FilePond with Django forms.
- Image Preview: Provides image preview functionality out of the box.
- Customization: Configurable options to tailor the widget to your needs.
- Responsive Design: Ensures a responsive and user-friendly interface.
- Simple Form Submission: Focuses on regular file field submissions with forms, without handling server API endpoints.
- Language Selection: Automatically sets the locale based on the current language, ensuring the FilePond interface matches the user's language preferences.
- Extensible: Support for additional FilePond plugins planned for future releases.
Note: This widget is designed to work with standard form submissions. While FilePond's server property can be configured for API endpoints, this is beyond the scope of this project which aims to provide a simple form widget implementation.
Installation
Install the package using pip:
pip install django-filepond-form-widget
Alternatively, you can install it from the repository:
pip install git+https://github.com/krystofbe/django-filepond-form-widget.git
Usage
Add to Installed Apps
Add django_filepond_form_widget to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
# ...
'django_filepond_form_widget',
# ...
]
Include Static Files
Ensure that your templates include the necessary static files. Typically, this is handled automatically by the widget's media.
Use the Widget in Forms
from django import forms
from django_filepond_form_widget.widgets import FilePondWidget
class ExampleForm(forms.Form):
image = forms.FileField(
widget=FilePondWidget(
config={"allowImagePreview": True, "allowMultiple": False}
)
)
Create Views and Templates
from django.shortcuts import render
from .forms import ExampleForm
def upload_view(request):
if request.method == "POST":
form = ExampleForm(request.POST, request.FILES)
if form.is_valid():
# Handle uploaded file
return render(request, "example_app/success.html")
else:
form = ExampleForm()
return render(request, "example_app/upload.html", {"form": form})
Plugins
Image Preview
To enable image preview, set the allowImagePreview option to True in the widget's config. You can also configure the following options:
imagePreviewMinHeight: Minimum image preview height.imagePreviewMaxHeight: Maximum image preview height.imagePreviewHeight: Fixed image preview height, overrides min and max preview height.imagePreviewMaxFileSize: Can be used to prevent loading of large images whencreateImageBitmapis not supported. By default no maximum file size is defined, expects a string, like "2MB" or "500KB".imagePreviewTransparencyIndicator: Set to 'grid' to render a transparency grid behind the image, set to a color value (for example '#f00') to set transparent image background color. Please note that this is only for preview purposes, the background color or grid is not embedded in the output image.imagePreviewMaxInstantPreviewFileSize: Maximum file size for images to preview immediately, if files are larger and the browser doesn't supportcreateImageBitmapthe preview is queued till FilePond is in rest state.imagePreviewMarkupShow: Set tofalseto hide image markup in the preview panel.imagePreviewMarkupFilter: Use to filter markup items, useful to show only certain items and hide others till the image file is generated by the image transform plugin.imagePreviewFilterItem: Use to filter file items before generating the preview, useful to filter certain image types or names if we do not wish to generate a preview. Receives a file item as the first argument. Returnfalseto skip generating an image preview. (item) => !/svg/.test(item.fileType) will skip generating previews for SVGs.
File Size Validation
To enable file size validation, set the allowFileSizeValidation option to True in the widget's config. You can also configure the following options:
minFileSize: The minimum size of a file (e.g., "1KB", "2MB").maxFileSize: The maximum size of a file (e.g., "5MB", "10MB").maxTotalFileSize: The maximum total size of all files (e.g., "10MB", "20MB").labelMaxFileSizeExceeded: Custom message when a file exceedsmaxFileSize.labelMaxFileSize: Custom message showing the max file size.labelMaxTotalFileSizeExceeded: Custom message when total size exceedsmaxTotalFileSize.labelMaxTotalFileSize: Custom message showing the max total file size.
Image Resize
To enable image resizing, set the allowImageResize option to True in the widget's config. You can also configure the following options:
imageResizeTargetWidth: The target width of the resized image in pixels.imageResizeTargetHeight: The target height of the resized image in pixels.imageResizeMode: The resizing mode ('cover', 'contain', or 'force').imageResizeUpscale: Whether to upscale images smaller than the target size (true or false).
File Type Validation
To enable file type validation, set the allowFileTypeValidation option to True in the widget's config. You can also configure the following options:
acceptedFileTypes: An array of accepted file types. Can be MIME types or wildcards. For example,['image/*']will accept all images, and['image/png', 'image/jpeg']will only accept PNGs and JPEGs.labelFileTypeNotAllowed: Custom message shown when an invalid file is added.fileValidateTypeLabelExpectedTypes: Custom message shown to indicate the allowed file types. Available placeholders are{allTypes},{allButLastType}, and{lastType}.fileValidateTypeLabelExpectedTypesMap: Allows mapping file types to more visually appealing labels. For example,{ 'image/jpeg': '.jpg' }will show.jpgin the expected types label. Set tonullto hide a type from the label.
Example:
from django import forms
from django_filepond_form_widget.widgets import FilePondWidget
class ExampleForm(forms.Form):
image = forms.FileField(
widget=FilePondWidget(
config={
"allowImagePreview": True,
"allowMultiple": False,
"allowFileSizeValidation": True,
"maxFileSize": "5MB",
"maxTotalFileSize": "10MB",
}
)
)
Example
An example project is provided to demonstrate how to integrate and run the widget.
Run the Development Server
Navigate to the example directory and run the server using Uvicorn:
uv run python example/manage.py runserver
Access the Application
Open your browser and navigate to http://localhost:8000/upload/ to see the file upload form in action.
Testing
This project uses pytest for testing. To run the tests:
Install Development Dependencies
uv pip install -e ".[test]"
Run Tests
pytest
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes with clear messages.
- Submit a pull request detailing your changes.
License
This project is licensed under the MIT License.
Metadata
Release files for django-filepond-form-widget 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_filepond_form_widget-0.3.0.tar.gz | 138.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_filepond_form_widget-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 244.8 kB
Release files / django_filepond_form_widget-0.3.0.tar.gz
| Download URL | django_filepond_form_widget-0.3.0.tar.gz |
|---|---|
| Size | 138.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fac388de9a08959c6a65f65851baa55be3940090b09d57e136934b95b48781b1
|
|
BLAKE2b-256 checksum How to use checksums |
f0955021d25491286dd011b98072b83840fa688626fdd4fe4ade4d9313e35caf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.14
|
Release files / django_filepond_form_widget-0.3.0-py3-none-any.whl
| Download URL | django_filepond_form_widget-0.3.0-py3-none-any.whl |
|---|---|
| Size | 106.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb74e30cc1b09cab92c0d3f3f83b9065b7c1a8af6a84533bf6ffaf989f0649f0
|
|
BLAKE2b-256 checksum How to use checksums |
46d8c3d2d54d4b2448cbdca64f3f05839ebaf7c6691032e474a25e5946ce848e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.14
|
Security for django-filepond-form-widget 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.