Django 1.10.5 Python 3.5.2 Jsignature

1.1k Views Asked by At

The app Jsignature is just what I need. It looks great. Unfortunate for me, I can't get it to work. Is this app the right app for Django 1.10.5 and Python 3.5.2?

I used the example code, made no changes and still I only get the button and not the signature field.

What I would like to do is this: With data from the site (filled in by the user) I create a pdf. Herefor I use Weasyprint and a template. This all works fine. Now I want to add a signature from the same template into de pdf as well. How do I do that? Can somebody help me?

1

There are 1 best solutions below

2
On BEST ANSWER
This is a new project and I only see the safe button:

settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'jsignature',
]

urls.py:
from django.conf.urls import url
from django.contrib import admin
from django.views.generic import TemplateView


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^sign/$', TemplateView.as_view(template_name='my_template.html'))
]

views.py:
from jsignature.utils import draw_signature
from myapp.forms import SignatureForm

def my_view(request):
    form = SignatureForm(request.POST or None)
    if form.is_valid():
        signature = form.cleaned_data.get('signature')
        if signature:
            # as an image
            signature_picture = draw_signature(signature)
            # or as a file
            signature_file_path = draw_signature(signature, as_file=True)

forms.py:
from django import forms
from jsignature.forms import JSignatureField


class SignatureForm(forms.Form):
    signature = JSignatureField()

my_template.html:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    {{ form.media }}
    <form action="." method="POST">
        {% for field in form %}
            {{ field.label_tag }}
            {{ field }}
        {% endfor %}
        <input type="submit" value="Save"/>
        {% csrf_token %}
    </form>
</body>
</html>

save button