In app.py I established a connection with my database then retrieved the data and stored it in a cursor object. I want to show the data on a web page so I transferred it with :
render_template('home.html', data=cursor)
Which works, it shows the data on my web page but when I refresh the page I get :
GET http://127.0.0.1:5000/static/css/template.css net::ERR_ABORTED 404 (NOT FOUND)
and my data doesn't show anymore.
app.py :
from flask import Flask, render_template
import sqlite3
import os.path
app = Flask(__name__)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(BASE_DIR, "movies.db")
with sqlite3.connect(db_path, check_same_thread=False) as db:
#I used check_same_thread=False to solve a same thread error
cursor = db.cursor()
cursor.execute("SELECT * FROM data")
@app.route("/")
def home():
return render_template('home.html', data=cursor)
if __name__== "__main__":
app.run(debug=True)
A piece of home.html :
<body>
{% extends "template.html" %}
{% block content %}
{% for item in data %}
<tr>
<td><a>{{item[1]}}</a></td>
</tr>
{% endfor %}
{% endblock %}
</body>
I want my web page to show the data without disappearing when I refresh my page.