I'm trying to save a pdf file which is rendered using HTML to a model field right now, it throws this error.
coercing to Unicode: need string or buffer, instance found
this is the code
def save_to_pdf(template_src, context_dict, pk):
import ipdb; ipdb.set_trace()
instance = get_object_or_404(
Project.objects.filter(pk=pk, is_deleted=False))
template = get_template(template_src)
context = Context(context_dict)
html = template.render(context)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result,link_callback=fetch_resources)
pdfnew=file(pdf)
instance.structural_info.save('structure.pdf',pdfnew)
return True
structural_info is the file field. What is the correct way to do it?