Can flask (using jinja2) render templates using 'windows-1251' encoding?


I write a simple frontend for pretty old reporting system, which uses Crystal Reports 8 Web Component Server.
And I need to make a ‘POST’ request to this Web Component. When I’m making request from page encoded using standard UTF-8, all form data is passed in UTF-8 too. And that’s the problem, because CR8 Web Component Server doesn’t understand UTF-8 (or does it and I’m wrong?).
I’ve tried to put accept-charset="ISO-8859-5" and accept-charset="windows-1251" in parameters and had no luck with it.

Here’s more info, that can be usefull:

  • This frontend will be working on Windows Server 2003 with IIS6,
  • Only suitable browser is IE, because CR8 Web Component Server uses ActiveX component. (There’s also a java plugin, but for some reason it doesn’t work at all).

So I need flask (jinja2) to render templates using ‘windows-1251’ encoding, because parameter names and values can contain cyrillic characters. It there any way I can achieve this?


I’ve found a simple (and maybe even stupid) solution.
Instead of return render_template('template.html', params**), I’m creating request manually and setting request data and headers to what i need.

And it looks like that:

r = Response()
    r.headers['Content-Type'] = 'text/html; charset=windows-1251' = render_template('template.html', param1 = data).encode('cp1251')

Looks like a dirty hack, but it works.

Answered By – zetdotpi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published