MCS 275 Spring 2024
Emily Dumas
Reminders and announcements:
python3 -m pip install Flask
Create the database
Write code to query the database and get a list of tasks
Make the task list HTML template
Single table tasks
with columns:
taskid
- integer primary keydescription
- stringowner
- stringstatus
- integer: 0=waiting, 1=in progress, 2=completecreated_ts
- "created timestamp" as
time.time()
updated_ts
- "updated timestamp" as
time.time()
Route /tasks/ddumas/
results in:
ddumas
owned tasksNote part of the URL is an argument. The pattern is /tasks/<username>/
Buttons on the task list view need to perform actions.
We'll make them links to certain URLs.
Using Flask, we'll make it so requesting those URLs performs the intended action.
A URL can include key-value pairs called query parameters, e.g.
https://example.com/find_section?course=MCS275&instructor=Dumas
Many ascii characters appear verbatim but others* become hexadecimal codes like %20
(for a space). So don't try typing a URL with parameters by hand.
Flask decodes the parameters and makes them available as
flask.request.values.get(key)
.
* The precise encoding scheme is specified in RFC3986.
/task/3/update?status=1
- Change status/task/3/update?shared=0
- Change privacy / sharing flag/task/3/delete
- Delete a task (add this later?)Question: What should the response to one of these look like?
Every HTTP request results in a numerical status.
So far, we've seen 404 (NOT FOUND) and 200 (OK, generated by Flask when we return HTML).
There are also codes that instruct the browser to load another resource, e.g. 302 (FOUND).
return flask.redirect("destination")
will make this happen.