Set class for a table

Asked

Viewed 233 times

5

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

Follow my example 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)

Is returning the table correctly, but wanted to include a class to the table.

  • Are you trying to implement an ORM? If you are trying I advise you to read more about sqlalchemy.

1 answer

2


In the project repository you have an example 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 watch out for the word classes be used as reference to assign CSS classes. Do not use it as the model field name.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.