チャコブラウザ🐶 #2 Flask Routing

ファイル構成

Fkask Routing用にFlaskフォルダを作成し、以下のファイル構成に変更しました。
./
├── Flask/
│   ├── app.py ←Flask Routing
│   │ 
│   ├── static/
│   │   ├──css/
│   │    │   └── style2.css
│   │   └──image/
│   │      └── DSC_7304.jpg
│   │ 
│   └── templates/
│   ├── lines.html ←BokehPlot
│   └── test.html ←チャコブラウザ
│ 
└── sht31_logger/
   ├── BME280.csv
   ├── esp32-3a.db ←外気温DB
   ├── http_post_13.py
   ├── mpl3115a2.py
   ├── sensor3.py
   └── sht31.db

SQLite DBの読み込み

  1. sqlite3をimport
  2. /sql ルートを定義
  3. select_sql():DB最新値を読み込みvalへ代入
  4. val をrender_template
app.py
#! /usr/bin/env python3
# _*_ coding: utf-8 _*_

from flask import Flask, render_template
import sqlite3

#app = Flask(__name__)
app = Flask(__name__, static_folder='static', template_folder='templates')

dbname  = '../sht31_logger/esp32-3a.db'


@app.route('/')
def index():
    return render_template('lines.html')

@app.route("/sql")
def select_sql():
	message = "Temperature"
	con = sqlite3.connect(dbname)
	cur = con.cursor()
	cur.execute('SELECT * FROM BME280 order by timestamp desc limit 1')
	val = cur.fetchone()
	cur.close()
	con.close()
	return render_template('test.html', message=message , val=val)

app.run(host='0.0.0.0', debug=True,)