Answer the question
In order to leave comments, you need to log in
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)
{% 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
{% 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 questionAsk a Question
731 491 924 answers to any question