K
K
kirillbeliy2021-05-07 12:22:08
SQLite
kirillbeliy, 2021-05-07 12:22:08

How to display data from database to website using python?

Hello! You just need to display data from a ready-made SQLite 3 database. Googled, but did not find anything
(

from flask import Flask, render_template, url_for, request
import sqlite3

app = Flask(__name__)
connect = sqlite3.connect('admin.db')
cur = connect.cursor()

@app.route('/')
@app.route('/home')
def index():
    cur.execute('SELECT * FROM players1')
    rows = cur.fetchall()
    return render_template("index.html", rows=rows)


@app.route('/about')
def about():
    return render_template("about.html")


if __name__ == "__main__":
    app.run(debug=True)

This is the html:
{% extends 'base.html' %}

{% block title %}
Таблица игроков
{% endblock %}

{% block body %}
<table>
    {% for row in rows %}
        <tr>
            <td>id</td>
            <td>name</td>
            <td>final</td>
        </tr>
    {% endfor %}
    </table>
{% endblock %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexbprofit, 2021-05-07
@kirillbeliy

{% for row in rows %}
        <tr>
            <td>row.id</td>
            <td>row.name</td>
            <td>row.final</td>
        </tr>
    {% endfor %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question