
Welcome!
Everything is fine.
Lab Day
I'd like to do a better job on some of the things we talked about yesterday.
- The Lookup assignment only uses GET, so you can ignore all our discussion of POST
- The FORM should specify the ACTION: the endpoint that will handle the form submission
url_for
:- takes 1 required positional argument, which is the name of the handler function, as a string
- takes any number of keyword arguments, which are the names of the arguments to the handler function and their values
Examples:
@app.route('/square/<num>')
def square(num):
n = float(num)
return ('<p>{x}<sup>2</sup> is {x2}</p>'.format(x=n, x2=n*n))
@app.route('/div/<num>/<denom>')
def div(num, denom):
ratio = float(num)/float(denom)
return('<p>{x} over {y} is {z}</p>'.format(x=num, y=denom, z=ratio))
url_for('square', num=18) # returns /square/18
url_for('div', num=4, denom=2) # returns /div/4/2
url_for('div', denom=2, num=4), # returns /div/4/2
Let's explore the solution
We'll walk through it very carefully and learn what we can:
- what does the FORM look like
- what do the requests look like
- what does the response chain look like
- anything else