Solution 1 :

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

Problem :

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:

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"


  <script type="text/javascript">

  $(document).ready(function() {
      var data = "{{dados}}"

      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"}];

        data: data,
        columns: columns
  } );


Comment posted by roganjosh

You haven’t shown your template

Comment posted by roganjosh

Also, are you using Python 2? You should be using Python 3 now, Python 2 is obsolete and no longer supported

Comment posted by Hasunohana

Updated, yeah, I’m using python 2, but I have an app py2 working

Comment posted by roganjosh

var data = "{{ dados | safe }}"