-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (32 loc) · 1.05 KB
/
app.py
File metadata and controls
40 lines (32 loc) · 1.05 KB
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
import sqlite3
from flask import Flask, render_template, request
def get_db_connection():
conn = sqlite3.connect('database.db')
conn.row_factory = sqlite3.Row
return conn
app = Flask(__name__)
@app.route('/')
def index():
conn = get_db_connection()
phones = conn.execute('select * from phones').fetchall()
conn.close()
return render_template('index.html', phones=phones)
@app.route('/item/<id>')
def get_item(id):
conn = get_db_connection()
result = conn.execute('select * from phones where id = ?', id).fetchone()
conn.close()
return render_template('item.html', phone=result)
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/compare')
def compare():
cookies = request.cookies
conn = get_db_connection()
phones = conn.execute('select * from phones where id in ' + '(' + cookies.get('compare') + ')').fetchall()
conn.close()
return render_template('compare.html', phones=phones)
@app.errorhandler(404)
def page_not_found(e):
return render_template("404.html"), 404