Quiz
- Could we go over python dictionaries again?
Sure. Python dictionaries are store key/value pairs. Some examples:
- When should we use custom exceptions vs. built-in exceptions?
The purpose of an exception is to report what went wrong. If there's a built-in exception that does a good job of describing that; use it. E.g.
DivideByZero
. ButInvalidCreditCard
would have to be a custom exception. - Can we practice the .execute, I'm still a little confused
Sure. That's part of the
PyMySQL
API. Let's try the following in a Python REPL: - How is the app.py module connected or related to pymysql and cs304dbi? In other words, could you go over the diagram you included at the beginning of the People App reading?
I'd be glad to: overview
the
import
statement adds new abilities to our python program. XKCD Python - Can we go over quiz question 4 about url_for() and make handler functions clear?
When we use the url_for() function A. We supply the URL we want B. We supply the name of the handler function C. We supply a route D. All of the above
Let's see it in action. Here's the code for app.py
So, you can see that the argument to
url_for
is the name of the handler function.A handler function is the function that is called when the browser sends a request with the paired endpoint (url).
- Could you talk more about the route decorator?
Yes. The route decorator associates an endpoint with a function.
The endpoint can have parameters, which Flask will parse for us.
The decorator can also specify what HTTP methods are supported. Default is
methods=['GET']
- Can you please go over
people_born_in_month()
handler function again? / Can we please go over parameterised routes and handler functions?Sure. We'll look at the code
This function is invoked when a request comes in that matches
/people-born-in/NNN
, where NNN is some number.Flask parses the URL and invokes our function with the number as an argument.
Our function is responsible for the response to the browser.
- what is the difference between these notations: {name} and {{name}}?
Great question. The idea of templating is common.
The single braces is for f-strings.
The double braces is for Jinja2, our file templating language.
- When I try to access and run the app.py file in ~cs304flask/pub/downloads/people_app (in the virtual environment), I receive an error:
ModuleNotFoundError: No module named 'cs304dbi'
Last time, we copied the
cs304dbi.py
file into our virtual environment. Maybe you missed that step? - I think I'm overall a little confused but practice should clear up my confusion / I don't have any specific questions, but think I'll feel more comfortable after reviewing this more
We'll do some practice!