Package: django-jsignature
A simple way to usejSignature jQuery pluginin yourDjangoprojects.It provides:A form field and a form widget to handle jquery plugin through a Django form;A model field to store a captured signature;A mixin adding two fields (signature / signature_date) in any of your Django models.A template filter to render signatures as base64 image urls.Installationpip install django-jsignatureUsageAddjsignatureto yourINSTALLED_APPS:# settings.pyINSTALLED_APPS=(...'jsignature',)Use provided model field (for easy storage):# models.pyfromdjango.dbimportmodelsfromjsignature.fieldsimportJSignatureFieldclassSignatureModel(models.Model):signature=JSignatureField()In your form template{{form.media}}<formaction=""method="post">{{form}}<inputtype="submit"value="Save"/>{%csrf_token%}</form>Render image from db value in your display template:{# yourtemplate.html #}{%loadjsignature_filters%}<imgsrc="{{obj.signature|signature_base64}}"alt="{{obj}}"/>By default, jSignature is made to work outside of admin, requiring that
you include the jQuery library in your<head>.If you want to use jSignature in the Django admin site, set theJSIGNATURE_JQUERYsetting toadmin. Otherwise if set to any url
pointing to jQuery, it will be automatically included.It is strongly suggested to take example fromexample_project, which islocated in this repoCustomizationJSignature plugin options are available in python:Globally, in your settings:# settings.pyJSIGNATURE_WIDTH=500JSIGNATURE_HEIGHT=200Specifically, in your form:# forms.pyfromjsignature.formsimportJSignatureFieldfromjsignature.widgetsimportJSignatureWidgetJSignatureField(widget=JSignatureWidget(jsignature_attrs={'color':'#CCC'}))Available settings are:JSIGNATURE_WIDTH(width)JSIGNATURE_HEIGHT(height)JSIGNATURE_COLOR(color)JSIGNATURE_BACKGROUND_COLOR(background-color)JSIGNATURE_DECOR_COLOR(decor-color)JSIGNATURE_LINE_WIDTH(lineWidth)JSIGNATURE_UNDO_BUTTON(UndoButton)JSIGNATURE_RESET_BUTTON(ResetButton)In your modelsIf you want to store signatures easily, a provided mixin gives asignatureand asignature_datethat update themselves:fromdjango.dbimportmodelsfromjsignature.mixinsimportJSignatureFieldsMixinclassJSignatureModel(JSignatureFieldsMixin):name=models.CharField()In your formsIf you need more precise handling of the form field, you can use it directly:# forms.pyfromdjangoimportformsfromjsignature.formsimportJSignatureFieldclassSignatureForm(forms.Form):signature=JSignatureField()And upon saving, have direct access to the image withdraw_signature()# views.pyfromjsignature.utilsimportdraw_signaturefrommyapp.formsimportSignatureFormdefmy_view(request):form=SignatureForm(request.POSTorNone)ifform.is_valid():signature=form.cleaned_data.get('signature')ifsignature:# as an imagesignature_picture=draw_signature(signature)# or as a filesignature_file_path=draw_signature(signature,as_file=True)Example projectIf you want to have a demo of this package, just use the example project:gitclonehttps://github.com/fle/django-jsignature.gitcddjango-jsignaturepython-mvenvvenvsourcevenv/bin/activatepipinstall-rrequirements.txtpipinstall-e.cdexample_project./manage.pymigrate./manage.pycreatesuperuserFill the user info, launch django with./manage.py runserverand head over
tohttp://127.0.0.1:8000/, you can alsologin to the adminwith the credentials your
provided.AuthorsFlorent Lebreton <florent.lebreton@makina-corpus.com> (original author)Sébastien Corbin <sebastien.corbin@makina-corpus.com> (maintainer)CHANGELOG0.12 (2024-01-27)** Bug fixed **Draw single points** New **Updated Github Actions.Dropped support for python < 3.8Dropped support for Django < 4.2Add support for pillow >= 10Updated jSignature to latest version0.11 (2022-01-17)** New **Django 4.0 compatibility.Moved to Github Actions for testing.Added flake8 in CI.Dropped support for python < 3.6Dropped support for Django 1.11, 2.0, 2.1, 3.0, 3.1.0.10 (2020-07-26)** New **Add template filter to easily render a signature structure as base64 url.Add a full example of front-office usage.0.9 (2020-04-18)** New **Add support for Django 2+Drop support for Django<1.11Add aJSIGNATURE_JQUERYsettings to handle usage in admin in Django 2.1+0.8 (2014-12-04)** New **Add support for Python 3 (@Gagaro)Add support for Django 1.7 (@Gagaro)0.7.6 (2014-11-26)** New features **A setting to display (or not) the reset button has been added (@jsayles)** Internal changes **Rendering is now based on a template (@andybak)Javascript is properly initialized (@andybak)