Django Jsignature not passing the form.is_valid()

微笑、不失礼 提交于 2021-01-29 09:05:13

问题


I am using jsignature:

https://github.com/fle/django-jsignature

I have managed to display the signature pad:

But when i tried to submit the form. i noticed that it could not pass the is_valid function and when i tried to printout the errors here is what i get:

<ul class="errorlist"><li>signature<ul class="errorlist"><li>This field is required.</li></ul></li></ul>

Here's my code in view:

form = SignatureForm(request.POST)

    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)
    else:

        print(form.errors)

Template:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>signature</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
</head>
<body>

    {{ form.media }}
    <form action="." method="POST">

        {% for field in form %}
            {{ field.label_tag }}
            {{ field }}
            <span style="color:red">{{ field.errors }}</span>
        {% endfor %}
        <input type="submit" value="Save"/>
        {% csrf_token %}
    </form>

</body>
</html>

forms.py

from django import forms
from jsignature.forms import JSignatureField


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

来源:https://stackoverflow.com/questions/59638551/django-jsignature-not-passing-the-form-is-valid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!