我在我的 django 项目中使用 django-jsignature。发出 post 请求后,表单返回“type 'instance'”。我试图将其另存为图像,但出现上述错误。
更好的是按照文档中的建议将表单数据保存为矢量图像。
我的功能:
def signature(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)
signature_file_path = draw_signature(signature, as_file=True)
with open(signature_file_path), 'wb') as f:
f.write(signature_picture)
(signature_file_path == '/tmp/tmpB71Wft.PNG')
最佳答案
我认为文档有点不清楚,但您应该使用 draw_signature(data, as_file=False)
(默认)或 draw_signature(data, as_file=True)
,两者都不需要。
通过 True
值为 as_file
制作包装 dump the image content to a file ,而False
使其返回 PIL.Image实例。
原始数据仍然可以在您的 signature
中找到。变量(作为 JSON 字符串或列表,因此您也可以直接使用该向量。
关于javascript - 类型错误 : must be string or buffer, 不是实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29861229/