Python - 'ascii' codec can't decode byte

前端 未结 7 604
旧巷少年郎
旧巷少年郎 2021-01-30 17:08

I\'m using Python 2.6 and Jinja2 to create HTML reports. I provide the template with many results and the template loops through them and creates HTML tables

When callin

7条回答
  •  鱼传尺愫
    2021-01-30 17:39

    From http://jinja.pocoo.org/docs/api/#unicode

    Jinja2 is using Unicode internally which means that you have to pass Unicode objects to the render function or bytestrings that only consist of ASCII characters.

    So wherever you set result.result_str, you need to make it unicode, e.g.

    result.result_str = unicode(my_string_variable, "utf8")
    

    (If your bytes were utf8 encoded unicode)

    or

    result.result_str = u"my string"
    

提交回复
热议问题