-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapp.py
More file actions
29 lines (25 loc) · 701 Bytes
/
app.py
File metadata and controls
29 lines (25 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import MySQLdb
import MySQLdb.cursors
from flask import Flask, render_template, json
app = Flask(__name__)
database = MySQLdb.connect(host = "localhost",
user = "anychart_user",
passwd = "anychart_pass",
db = "anychart_db",
cursorclass = MySQLdb.cursors.DictCursor)
cursor = database.cursor()
@app.route("/")
def main():
cursor.execute("SELECT name, value FROM fruits ORDER BY value DESC LIMIT 5")
data = cursor.fetchall()
chart = {
"chart": {
"type": "pie",
"title": "Top 5 fruits",
"data": data,
"container": "container"
}
}
return render_template("index.html", title = "Anychart Python template", chartData = json.dumps(chart))
if __name__ == "__main__":
app.run()