Define class for a table

5

I'm starting now with Flask and I came across the following question: how do I define a table class using flask_table ?

Here is my sample code and the result:

from flask_table import Table, Col

class TabelaDados(Table):
    codigo = Col('Código')
    nome = Col('Nome')
    ip = Col('Ip')

@app.route('/dados')
def dados():
    dados_pc = TI.query.all()
    table = TabelaDados(dados_pc)
    print(table.__html__())
    return render_template('dados.html', tabela=table)

You are returning the table correctly, but wanted to include a to the table.

    
asked by anonymous 04.05.2015 / 23:03

1 answer

2

In the project repository there is a sample folder. Here has an example of how to reference classes in the table.

class TabelaDados(Table):

    classes = ['tabela-fixa', 'tabela-pequena']

    codigo = Col('Código')
    nome = Col('Nome')
    ip = Col('Ip')

Just be careful if the word classes is used as a reference for assigning CSS classes. Do not use it as the model's field name.

    
15.05.2015 / 01:14