MCS 275 Spring 2021
Emily Dumas
Course bulletins:
This is the last in our lecture series focused on live coding two web applications (source here):
* Additional refinements outside lecture.
* Copied from chat app with minor changes.
/
- (GET) show message feed/post
- (POST) add message/top/
- (GET) show items, ranked/new/
- (GET) show items, chrono/post
- (POST) submit item/plus?postid=15
- (GET) score += 1/minus?postid=15
- (GET) score -= 1url_for(func_name,param1=val1,param2=val2,...)
- Get URL corresponding to a function within this application, with optional query parameters, e.g.
url_for("record_score",postid=5,score=11)
might return "/setscore?postid=5&score=11"
if your app contains:
@app.route("/setscore")
def record_score():
print("recording score {} for postid {}".format(
flask.request.values.get("score"),
flask.request.values.get("postid"),
)
redirect(url)
- Returning this object from a route will cause the HTTP server to issue a 302 response, redirecting the client to url
. (Basically, it means "ask them to load a different URL")abort(http_error_code)
- Immediately stop and return a HTTP error code (usually 400 bad request, 401 not authorized, 403 forbidden, or 404 not found).Some of the things you'd do differently in a "real" application: