i am trying to implement a jsignature plug in to my django appplication via django-jsignature3 , however it seems that i am unable to get it to save to my database.
here is my code:
models.py
class JSignatureModel(JSignatureFieldsMixin):
name = models.CharField(max_length=20)
views.py
def my_view(request):
form = SignatureForm(request.POST or None)
print('in view')
if form.is_valid():
signature = form.cleaned_data.get('signature')
print('form is valid')
if signature:
# as an image
print('found sig')
signature_picture = draw_signature(signature)
# or as a file
signature_file_path = draw_signature(signature, as_file=True)
return render(request, 'cash/jsig.html', {'form': form })
jsig.html
{% extends 'base.html' %}
{% load static %}
{%load crispy_forms_tags%}
{% block content %}
<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>
{%endblock content%}
url.py
path('jsig/', views.my_view , name='jsig')
forms.py (this is really iffy to me , i don't understand the documentation , there is no place that my model was called , hence i did this my self but it does not work)
class SignatureForm(forms.Form):
signature = JSignatureField()
class Meta:
model = JSignatureModel
fields = ['name','signature']
exclude = []
here is my console
[04/Apr/2020 01:14:43] "GET /jsig/ HTTP/1.1" 200 5593
in view
form is valid
found sig
[04/Apr/2020 01:14:46] "POST /jsig/ HTTP/1.1" 200 5959
Please help , im really confused!