forked from rickiepark/python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflask7.py
More file actions
64 lines (35 loc) · 822 Bytes
/
Copy pathflask7.py
File metadata and controls
64 lines (35 loc) · 822 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# coding: utf-8
# In[1]:
import os
import sqlite3
from models.user import User
# In[2]:
from flask import Flask, request, render_template, g
# In[3]:
app = Flask(__name__)
app.config.from_object(__name__)
# In[4]:
app.config.update(dict(
DATABASE=os.path.join(app.root_path, 'flask_test.db')
))
# In[5]:
def connect_db():
if not hasattr(g, 'db_con'):
g.db_con = sqlite3.connect(app.config['DATABASE'])
g.db_con.row_factory = sqlite3.Row
return g.db_con
# In[6]:
@app.teardown_appcontext
def close_db(error):
if hasattr(g, 'db_con'):
g.db_con.close()
# In[7]:
@app.route('/list')
def list():
db = connect_db()
u = User(db)
usernames = u.get_list()
return render_template('list2.html', users=usernames)
# In[8]:
app.run()
# In[ ]: