Base64 Decode String in jinja [duplicate]

瘦欲@ 提交于 2020-01-02 05:42:08

问题


I'm new to using python and flask and really like it. I'm returning a query to be displayed in a jinja template and one of my columns being returned has base64 data. How do I decode that data and display it.


回答1:


In jinja To work with Base64 encoded strings:

{{ encoded | b64decode }}
{{ decoded | b64encode }}

For more http://docs.ansible.com/ansible/playbooks_filters.html




回答2:


You can try to write custom filter

# add filter to jinja2 env
environment.filters['b64decode'] = base64.b64decode

# in template use
{{ value|b64decode }}


来源:https://stackoverflow.com/questions/39047657/base64-decode-string-in-jinja

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!