Quiz

  1. What is the difference between uid and gid?

    UID is the User ID. GID is the Group ID. These are unique identifiers in two databases: one of users and one of groups.

    For example, my uid is 716. I'm in the faculty group, which is gid 501.

    Our version of Linux creates a group for each user, so most of you are in a group of one. But the sysadmin can modify your group if desired.

  2. What does sudo do?

    It allows you do commands restricted to the "super user" (AKA Administrator AKA root).

    (Actually, it just means "switch user" but 99.99% of the time it's used to switch to root.)

    You are admin on your own laptop, but not on Tempest (the CS server).

  3. I'm having a hard time connecting all of the different things mentioned in the reading and forming a coherent big picture.

    Yep, that's very common. We'll go back to our organizing picture and review.

  4. What is the relationship between Apache, Flask, and Tempest?

    Apache is a web server. (There are others, like Nginx, IIS, etc.) That means it listens to the network for web requests (HTTP and HTTPS) and responds to them.

    Flask allows us to set up a web server for developing our app. It also listens for web requests and responds. Usually, it's our code that runs to actually do the response. But Flask takes care of a lot of necessary stuff: parsing the request, routing it to the correct function, etc.

    Tempest is a computer that Apache and Flask are running on.

  5. I'm confused about the distinction between ports, requests, and database connections. What does it meant to say Flask is handling one of these?

    When Flask runs, it has to open a port: a numbered door to listen for requests. We all have to use different ports.

    A request is when a browser asks a server for a web page. There are two kinds: GET and POST, like we talked about last time. Most requests are GET requests for a simple URL.

    "Handling a request" means providing a web page in answer to the request.

    When our Flask (Python) code runs, it has the option of connecting to the database and getting data from it.

  6. What are the main benefits of Flask?

    Takes care of a lot of the necessary but routine infrastructure for creating a web application. Every web application has to parse the request, route it to the appropriate handler, package up the result (adding HTTP headers and such). Why not centralize that in a shared library?

  7. Can you go over routing, setting up flask?

    We will!

  8. Can you explain what the code within the routing section is doing? I'm confused why the /hello/ inside @app.route() would lead to the greeting function. Is the @app.route('/hello/') directly above the greeting function routing /hello to the function? What happens if that line comes after the function?

    Sure! Let's look at the routing section.

    I think what you're confused about is the magic decorator syntax. I'll do a brief aside on that, but most students end up treating it as, well, magic syntax.

    Conceptually, Flask sets up a dictionary mapping endpoints (parts of a URL) to functions (to handle that endpoint). The @route decorator pairs an endpoint with a function.

  9. For routing, would you need to add a @app.route statement before every single function you define?

    Yep.

  10. Are there best practices for organizing where different virtualenvs for different projects are located? Does it matter what folder you have a virtualenv in?

    Typically, the venv is a subdirectory of the project directory, but there are lots of variations on that theme.

    It doesn't really matter. The python modules will be loaded from the venv and from the local files, which don't have to be co-located.

  11. Can you show us an example with Virtualenv in practice? I'm a bit confused about what you mean when you say, "each virtualenv is independent."

    We'll set one up today. By saying a "virtualenv is independent" it means that modules in one venv don't have to have anything to do with the modules in another. One can have Flask 1.1.1 and another can have Flask 2.3.3. They can even be for different versions of Python, say 3.6 versus 3.9. (In fact, I have just that situation.)