1 of 38

2 of 38

This is CS50

  • Visit cs50.ly/screen to view projector on your laptop and ask questions via chat.
  • Today's snack, fruit snacks and roll-ups!
  • Last CS50 Lunch this Fri 11/17 at 1:15pm! RSVP at cs50.ly/lunch!
  • Do say hi or ask questions (or ask for stress ball 🔴) during break or after class!

3 of 38

4 of 38

http-server

5 of 38

https://www.example.com/

6 of 38

https://www.example.com/file.html

7 of 38

https://www.example.com/folder/

8 of 38

https://www.example.com/folder/file.html

9 of 38

https://www.example.com/path

10 of 38

https://www.example.com/route

11 of 38

https://www.example.com/route?key=value

12 of 38

https://www.example.com/route?key=value&key=value

13 of 38

GET /search?q=cats HTTP/2

Host: www.google.com

...

14 of 38

Flask

15 of 38

flask run

16 of 38

app.py

requirements.txt

static/

templates/

17 of 38

app.py

requirements.txt

static/

templates/

18 of 38

from flask import Flask, render_template

app = Flask(__name__)

@app.route("/")

def index():

return render_template("index.html")

19 of 38

request.args

20 of 38

Jinja

21 of 38

request.form

22 of 38

23 of 38

Controller

View

24 of 38

Controller

View

Model

25 of 38

26 of 38

GET / HTTP/2

Host: accounts.google.com

...

27 of 38

HTTP/2 200

Content-Type: text/html

...

28 of 38

HTTP/2 200

Content-Type: text/html

Set-Cookie: session=value

...

29 of 38

GET / HTTP/2

Host: accounts.google.com

...

30 of 38

GET / HTTP/2

Host: accounts.google.com

Cookie: session=value

...

31 of 38

session

32 of 38

from cs50 import SQL

33 of 38

[

{"id": 1, "title": "The Hitchhiker's Guide to the Galaxy"},

{"id": 2, "title": "The Restaurant at the End of the Universe"},

{"id": 3, "title": "Life, the Universe and Everything"},

{"id": 4, "title": "So Long, and Thanks for All the Fish"},

{"id": 5, "title": "Mostly Harmless"},

]

34 of 38

API

35 of 38

[

{"id": 112108, "title": "The Office", "year": 1995, "episodes": 6},

{"id": 290978, "title": "The Office", "year": 2001, "episodes": 14},

{"id": 386676, "title": "The Office", "year": 2005, "episodes": 188},

{"id": 1791001, "title": "The Office", "year": 2010, "episodes": 30},

{"id": 2186395, "title": "The Office", "year": 2012, "episodes": 8},

{"id": 8305218, "title": "The Office", "year": 2019, "episodes": 28},

{"id": 20877972, "title": "The Office", "year": 2022, "episodes": 20},

]

36 of 38

JSON

37 of 38

[

{"id": 112108, "title": "The Office", "year": 1995, "episodes": 6},

{"id": 290978, "title": "The Office", "year": 2001, "episodes": 14},

{"id": 386676, "title": "The Office", "year": 2005, "episodes": 188},

{"id": 1791001, "title": "The Office", "year": 2010, "episodes": 30},

{"id": 2186395, "title": "The Office", "year": 2012, "episodes": 8},

{"id": 8305218, "title": "The Office", "year": 2019, "episodes": 28},

{"id": 20877972, "title": "The Office", "year": 2022, "episodes": 20}

]

38 of 38