Quiz
- What is the purpose of using virtualenv? Can you give an example involving different projects? / Could you go over virtualenv again? / I am still confused on virtualenv
Sure. Suppose you are working in CS 304 and you need Flask, PyMySQL, Bcrypt and a few other modules. You need to install them, so you need to use virtualenv, since you are not an admin for the CS server.
Suppose you are also in, say, bioinformatics course and you need to install a bunch of Python modules for that course. You could install them in the same venv, but maybe they don't play well together. So, you decide to install them in a different venv.
A venv is just like a folder of Python modules. It's just set up so that Python knows to import modules from that folder.
- Does flask have to be run in a virtual environment? / Are we always using the virtualenv for flask and python?
Flaskk doesn't require venv; Flask doesn't care where you get your modules from.
Venv just allows you to install a module of your own.
Yes, we'll use venv
- Can we review ports?
Glad to. Different services listen for packets on different ports, just like different offices in Green Hall.
A port is just a numbered door on the server.
Apache listens on 80 and 443, SSH on 22, mail on 25, and our development versions of flask will run on our own UID.
- Could we go over routing? Does only one function map to one URL?
Yes, pretty much. When a request comes in, the Flask intrastructure parses the URL and passes the request off to one of our handlers, to, well, handle it. That's the routing.
- How is .route() used? / Could you explain what @app.route() does ?
It establishes a correspondence between a function we write and an endpoint. You essentially are telling the Flask infrastructure: when a request comes in with a URL that ends like this, call that function.
- Can we go over the 1:1 correspondence of routes (URLs) to handler functions again?
- And how does the function work if I defined it but never called it?
The Flask infrstructure calls it! The great thing about using Flask is that you don't have to deal with the low-level network stuff, but the consequence is that you have to hook into its way of calling your code.
- What if we have multiple functions under one route?
It's possible to assign a function to multiple endpoints, but we won't do that often, if at all. Let's start simple.
- How do those urls that have different names work? Is it also through handler? (like when you rename your linkedin url)
I'm not sure what you mean by urls that have different names.
- can you explain development mode versus production mode further?
Sure. We will always be in development mode. So, it might not feel like you are creating a "real" web application. But you are: all but the last step, which is to deploy it. And you can do that if you want.
- I'm still confused by the difference between development and production mode. How do we switch between the two modes (in a mechanical sense)?
/ Could you talk more about deploy vs. development mode & the transition between the modes?
You don't switch. That involves interacting with the sysadmin (me). We'll discuss later in the course.
- What does localhost in our browser do?
Localhost is a universal hostname meaning "the host that I am on". Like the pronoun "me".
- Is the off-campus SSH tunnel anything similar to the first lab? Still a bit confused on how to set it up.
Not really. They both involve SSH, but the tunnel is some extra machinery to transfer network packets between the remote machine and your localhost (your laptop).
- Could you share a bit on how the different engines work? like the new jinja2 templating engine, innodb storage engine?
Alas, the word "engine" is overworked. Innodb is a different data structure for table representation. Jinja2 is a language for combining data with HTML.
- I don't think I have a specific question I would just like more practice.
For sure! Let's get to it!