UnicodeEncodeError: кодек 'latin-1' не может кодировать символы в позиции 1135-1137: ordinal not in range(256)
Я пытаюсь на Django перевести из html в pdf ежемесячный отчет, который берет данные из базы данных. на иврите. У меня есть проблема, которую я не могу решить уже несколько дней. Когда я отображаю данные на английском языке, pdf работает правильно и все в порядке, но когда я хочу отобразить данные на иврите из базы данных, он не позволяет мне это сделать и появляется следующая ошибка: 'latin-1' codec can't encode characters in position 1135-1137: ordinal not in range(256)
Я уже пробовал несколько решений:
- I changed the font several times in the base html of the PDF via the css and it just does not help at all.
- I tried to change the rendering function I have at the moment and it also did not help at all.
Моя функция рендеринга :
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return None