带Flask/Python和MySQL的可编辑CRUD表

2024-05-14 14:06:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Python Flask实现一个包含CRUD操作的可编辑表。 基本上我找到的每个教程都使用PHP。在

我看到了两张我喜欢的桌子:

Patternfly In Line Editing for Table View

jQuery Tabledit Example #6

我已经有了连接到数据库的Python代码:

def export_ledger():
    cnx = mariadb.connect(  user=cfg.db['user'],
                            password=cfg.db['pwd'],
                            database=cfg.db['baseteste']
                            )
    cursor = cnx.cursor()

    query = """
            SELECT ID, data, credito, debito, descricao, valor
            FROM ledger_teste
            ORDER BY data DESC
            """

    cursor.execute(query)
    rows = cursor.fetchall()
    desc = cursor.description
    cnx.close()

    ledger_completo = [dict(itertools.izip([col[0] for col in desc], row)) 
        for row in rows]

    return json.dumps(ledger_completo) 

但是我仍然需要编写代码来编辑显示的条目,并删除条目。在

我尝试在HTML中使用以下JavaScript代码进行Ajax连接,但没有成功:

^{pr2}$

我的问题是:如何使这个Python代码产生的JSON作为表的提要,以及如何添加函数来编辑和删除条目?在

事先非常感谢。在


Tags: 代码编辑fordbdata条目querycfg

热门问题