Django 1.10.5 Python 3.5.2 Jsignature

时间:2017-01-24 14:34:41

标签: jsignature

app Jsignature正是我需要的。看起来不错。不幸的是,我无法让它发挥作用。这个应用程序是Django 1.10.5和Python 3.5.2的正确应用程序吗?

我使用了示例代码,没有做任何更改,但我只得到按钮而不是签名字段。

我想做的是: 使用来自站点的数据(由用户填写),我创建了一个pdf。为此我使用Weasyprint和模板。一切正常。 现在我想将同一模板中的签名添加到de pdf中。我怎么做?有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

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