Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base64 Decode String in jinja [duplicate]

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.

like image 319
skellington Avatar asked Aug 19 '16 21:08

skellington


2 Answers

In jinja To work with Base64 encoded strings:

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

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

like image 169
Ruhul Amin Avatar answered Nov 10 '22 09:11

Ruhul Amin


You can try to write custom filter

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

# in template use
{{ value|b64decode }}
like image 27
Maks Skorokhod Avatar answered Nov 10 '22 11:11

Maks Skorokhod