1

i have problem with this error 'latin-1' codec can't encode characters in position 51732-51735: ordinal not in range(256) how can i solve that problem?

this is my views.py code

def render_to_pdf(template_src, context_dict={}):
    template = get_template(template_src)
    html  = template.render(context_dict)
    result = io.StringIO()
    pdf = pisa.pisaDocument(io.StringIO(html.encode("ISO-8859-1")), result)
    if not pdf.err:
        return HttpResponse(result.getvalue(), content_type='application/pdf')
    return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))    
def myview(request, pk):
    postingan_list = Pengajuan_SKTM.objects.filter(id=pk)
    return render_to_pdf(
            'pengurusan/pdf_template.html',
            {
                 'pagesize':'A4',
                 'postingan_list' : postingan_list,
            })

and this is my urls.py code

url(r'^(?P<pk>[0-9]+)/myview/$', views.myview, name='print')
Naufal
  • 89
  • 2
  • 8

1 Answers1

1

You probably try to render some Unicode characters, which are not present in the ISO-8859-1 encoding. If underlying library supports that (and everything nowadays should), use UTF-8 as it has support for all characters.