Skip to main content

A Django field for capturing signatures using signature_pad

Project description

Django Signature Pad

Django model field and form widget for capturing signatures using szimek signature_pad.

By design, signatures are stored as PNG images encoded as data URLs. This means:

  • Signatures can only be displayed as images after being saved
  • Signatures cannot be loaded back into the signature pad for editing
  • To modify a signature, users must draw a new one from scratch
  • This design decision was made to ensure signature integrity and simplify storage requirements.

django_signature_pad.png

⚠️ Important Note: This package does not include the signature_pad JavaScript library. You need to install it separately following the instructions on GitHub.

📦 Common installation methods include:

  • Using npm: npm install signature_pad
  • Using a CDN: <script src="https://cdn.jsdelivr.net/npm/signature_pad@5.0.4/dist/signature_pad.umd.min.js"></script>
  • Downloading directly from GitHub releases

Security Features

The SignaturePadField includes several security features:

  • Data URL format validation
  • Base64 encoding verification
  • PNG signature verification
  • Size limitation (default: 100KB)

These safeguards help protect against malicious input and ensure data integrity.

Installation

pip install django-signature-pad

Quick Start

  1. Add "signature_pad" to your INSTALLED_APPS:
INSTALLED_APPS = [
    ...
    'signature_pad',
]
  1. Use the field in your models:
from django.db import models
from signature_pad import SignaturePadField

class Document(models.Model):
    signature = SignaturePadField(blank=True, null=True)
  1. Create a form for your model:
from django import forms
from .models import Document

class DocumentForm(forms.ModelForm):
    class Meta:
        model = Document
        fields = ['signature']  # Include other fields as needed
  1. Use the form in your template:
{{ form.media }}
<form method="post">
  {% csrf_token %} {{ form.as_p }}
  <button type="submit">Save</button>
</form>
  1. Render signature image:
<img src="{{ obj.signature }}" alt="Signature" />

Widget customization (optional):

from django import forms
from signature_pad import SignaturePadWidget
from .models import Document

class DocumentForm(forms.ModelForm):
    signature = forms.CharField(
        widget=SignaturePadWidget(
            dotSize=2.5,
            minWidth=1.0,
            maxWidth=4.0,
            backgroundColor="rgb(240, 240, 240)",
            penColor="rgb(0, 0, 255)"
        )
    )

    class Meta:
        model = Document
        fields = ["name", "signature"]

Available customization options:

dotSize: Size of the drawing dot (float)
minWidth: Minimum width of the signature line (float)
maxWidth: Maximum width of the signature line (float)
backgroundColor: Canvas background color (CSS color string)
penColor: Signature line color (CSS color string)

Example Project

Want to see it in action? Try the example project:

# Clone the repository
git clone https://github.com/hleroy/django-signature-pad.git
cd django-signature-pad

# Setup the example project (uv installs dependencies automatically)
uv run python example_project/manage.py migrate
uv run python example_project/manage.py createsuperuser

Fill in the superuser information when prompted. Then start the development server:

uv run python example_project/manage.py runserver

Visit http://127.0.0.1:8000/ to see the demo in action. You can also access the admin interface http://127.0.0.1:8000/admin using the credentials you just created.

If you want to access the demo from your smartphone connected to the same (Wi-Fi) network as your computer, start the development server with 0.0.0.0:8000:

uv run python example_project/manage.py runserver 0.0.0.0:8000

License

This project is licensed under the MIT License - see the LICENSE file for details.

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_signature_pad-0.9.1.tar.gz (76.0 kB view details)

Uploaded Source

Built Distribution

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

django_signature_pad-0.9.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file django_signature_pad-0.9.1.tar.gz.

File metadata

  • Download URL: django_signature_pad-0.9.1.tar.gz
  • Upload date:
  • Size: 76.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for django_signature_pad-0.9.1.tar.gz
Algorithm Hash digest
SHA256 201d4b7c268a32072652d96b334693b390acdf452c6cf0c39c04dade43c7ea74
MD5 74009f8de77d4b4bfc5fa2ae561e9007
BLAKE2b-256 c42b38d3d2da93a68790fa1251015e5e4a1ddd474d3e9d6df1738697527a4d7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_signature_pad-0.9.1.tar.gz:

Publisher: publish.yml on hleroy/django-signature-pad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_signature_pad-0.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_signature_pad-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6609f84a72489d4f8a857597cdee9aec5eed0c48758cba6673d5857ee40a833c
MD5 f32dc929ccc8aafe8441635b7dc02a06
BLAKE2b-256 0eaa17dfa6e97d3f4ea957ab9f451cd5b81c0d9683cf0ee6e9af9f13855df0aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_signature_pad-0.9.1-py3-none-any.whl:

Publisher: publish.yml on hleroy/django-signature-pad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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