Add |safe to disable automatic escaping.
var data = "{{ dados|safe }}"
Alternatively, you could use a jinja for loop to add rows to the table and not have to use any jquery
Add |safe to disable automatic escaping.
var data = "{{ dados|safe }}"
Alternatively, you could use a jinja for loop to add rows to the table and not have to use any jquery
I am trying to pass the data obtained through a select to a table, however I realize that there is a problem with “character encoding”, I think.
This example is the data output straight from the function that pulls data from the database:
[{'NOME': 'FULANO', 'BAIRRO': u'Barxe3o', 'CIDADE': u'Lenxe7a', 'RUA': u'R. Machado', 'SERVICO': u'Instalaxe7xe3o', 'ID': '83070'},
Now I render my template with the datas, simple way:
@app.route('/')
def index():
return render_template('index.html',dados=getAllOS())
Output using console log:
[{'NOME': 'FULANO', 'BAIRRO': u'Barão', 'CIDADE': u'Lença', 'RUA': u'R.Machado', 'SERVICO': u'Instalação', 'ID': '83070'},
I can’t remove this encoding, it prevents me from using bootstrapTable or DataTable to write my table, as it doesn’t identify the column names with the objects.
<table id="table1" data-toggle="true"
data-toolbar="#toolbar"
data-search="true"
data-show-columns="true"
data-pagination="true"
data-height="500">
</table>
<script type="text/javascript">
$(document).ready(function() {
var data = "{{dados}}"
console.log(data);
var columns = [{"field": "ID", "sortable": true, "title": "ID"}, {"field": "NOME", "sortable": true, "title": "NOME"},
{"field": "SERVICO", "sortable": true, "title": "SERVICO"}, {"field": "CIDADE", "sortable": true, "title": "CIDADE"},
{"field": "BAIRRO", "sortable": true, "title": "BAIRRO"},
{"field": "RUA", "sortable": true, "title": "RUA"}];
$('#table1').bootstrapTable({
data: data,
columns: columns
});
} );
</script>
You haven’t shown your template
Also, are you using Python 2? You should be using Python 3 now, Python 2 is obsolete and no longer supported
Updated, yeah, I’m using python 2, but I have an app py2 working
var data = "{{ dados | safe }}"