I am working on Flask app that will get the data from my sqlite3 database and push it to the index.html. For some reason i am getting the error when I execute the code:
from flask import Flask, render_template, request
app = Flask(__name__)
import sqlite3
# Retrieve data from database
def getData():
conn=sqlite3.connect('../Sensors.db')
curs=conn.cursor()
for row in curs.execute("SELECT * FROM BME_DATA ORDER BY TIME_STAMP DESC LIMIT 1"):
Time = str(row[1])
Temperature = row[2]
Gas = row[3]
Humidity = row[4]
Pressure = row[5]
Altitude = row[6]
conn.close()
return Time, Temperature, Gas, Humidity, Pressure, Altitude
# main route
@app.route("/")
def index():
Time, Temperature, Gas, Humidity, Pressure, Altitude = getData()
templateData = {
'Time': Time,
'Temperature': Temperature,
'Gas': Gas,
'Humidity': Humidity,
'Pressure': Pressure,
'Altitude': Altitude
}
return render_template('index.html', **templateData)
if __name__ == "__main__":
app.run(debug=False)
The flask app is located ad BMEWebServer folder. And the structure I have looks like this:
BMEWebServer/appBMEWebServer.py
BMEWebServer/templates/style.css
BMEWebServer/static/index.html
The error I am getting is this:
>>> %Run appBMEWebServer.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2019-03-01 01:45:32,774] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python3/dist-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python3/dist-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3/dist-packages/flask/_compat.py", line 33, in reraise
raise value
File "/usr/lib/python3/dist-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3/dist-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/pi/Desktop/Sensors_Database/BMEWebServer/appBMEWebServer.py", line 30, in index
return render_template('static/index.html', **templateData)
File "/usr/lib/python3/dist-packages/flask/templating.py", line 133, in render_template
return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 851, in get_or_select_template
return self.get_template(template_name_or_list, parent, globals)
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 812, in get_template
return self._load_template(name, self.make_globals(globals))
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 774, in _load_template
cache_key = self.loader.get_source(self, name)[1]
File "/usr/lib/python3/dist-packages/flask/templating.py", line 57, in get_source
return self._get_source_fast(environment, template)
File "/usr/lib/python3/dist-packages/flask/templating.py", line 85, in _get_source_fast
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: static/index.html
127.0.0.1 - - [01/Mar/2019 01:45:32] "GET / HTTP/1.1" 500 -
127.0.0.1 - - [01/Mar/2019 01:45:34] "GET /favicon.ico HTTP/1.1" 404 -
Any ideas what am I doing wrong here?