Skip to main content

A Django form widget using FilePond with image preview support

Project description

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})

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:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Commit your changes with clear messages.
  4. Submit a pull request detailing your changes.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_filepond_form_widget-0.1.5.tar.gz (134.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_filepond_form_widget-0.1.5-py3-none-any.whl (100.2 kB view details)

Uploaded Python 3

File details

Details for the file django_filepond_form_widget-0.1.5.tar.gz.

File metadata

File hashes

Hashes for django_filepond_form_widget-0.1.5.tar.gz
Algorithm Hash digest
SHA256 bbbbf7b8fe2cfbbd6628242605b09c5dcdfbd0513c123fdca58b7aa6069835d5
MD5 02118f68c48d5261138044159ece3ab8
BLAKE2b-256 fff8620bc6f0afcb4476d76da42acb9fb7a9cb3b05548840d2c607cbf3146bf7

See more details on using hashes here.

File details

Details for the file django_filepond_form_widget-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_filepond_form_widget-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8f44d4bcd38874e56c9d7855283cabf1789133b7927fcf51cf69e53b4de0e80a
MD5 9acb39a491aaecbf0e3b2e1d9e5288d0
BLAKE2b-256 0951d8dfd209fb5dd0b6c4590e5425da64817d7231ea8f90d011c0593abc790b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page