Skip to content

Commit f647f14

Browse files
committed
Update dependencies and add book index route
Updated `Pipfile.lock` to specify Python 3.8 and added dependencies including `click`, `flask`, `itsdangerous`, `jinja2`, `markupsafe`, `python-dotenv`, and `werkzeug` with version constraints and hashes. Added a new route in `routes.py` for the index page that handles GET requests, retrieves query parameters for `name`, `author`, and `read`, and executes SQL queries to fetch and render books using the `books.html` template.
1 parent c6f4d20 commit f647f14

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

samples/Pipfile.lock

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/routes.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
from flask import request, render_template, make_response
3+
4+
from server.webapp import flaskapp, cursor
5+
from server.models import Book
6+
7+
8+
@flaskapp.route('/')
9+
def index():
10+
name = request.args.get('name')
11+
author = request.args.get('author')
12+
read = bool(request.args.get('read'))
13+
14+
if name:
15+
cursor.execute(
16+
"SELECT * FROM books WHERE name LIKE '%" + name + "%'"
17+
)
18+
books = [Book(*row) for row in cursor]
19+
20+
elif author:
21+
cursor.execute(
22+
"SELECT * FROM books WHERE author LIKE '%" + author + "%'"
23+
)
24+
books = [Book(*row) for row in cursor]
25+
26+
else:
27+
cursor.execute("SELECT name, author, read FROM books")
28+
books = [Book(*row) for row in cursor]
29+
30+
return render_template('books.html', books=books)

0 commit comments

Comments
 (0)