I'm sure you're not alone. That's the single most frequently asked question.
In CS 111, you understand small blocks of code. In 230, medium blocks of code, maybe larger. In 304, we understand large, multi-part programs.
A cursor is a object with methods to send SQL to the
server, and fetch the results back. Those are execute
and fetchone/fetchall
respectively.
When we run a program, code gets read from disk and goes into memory (RAM). Importing reads more code from disk into RAM.
So, yes, you are really adding code to your program. Your program happens to be build out of modules.
We can also read other text files into our program, such as template files or CNF files. Instead of reading them each time we want them, we can save them in memory. That's also called caching, but a different kind of caching than browser caches.
Caching is a ubiquitous technique to avoid doing something repeatedly. Here is a kind of cache:
Your assignments and projects will be built in a similar manner, out of similar parts, using similar coding techniques.
You will never import it.
Metaphor: You will be building cars in this course. This is a car that I built.
You will practice it a zillion times in this course. If your project has an "/profile" page, you will write something like:
That's what the Python language gives us. It's a nice way to allow one file to be either a module, useable in other programs, and also to be a program itself. Sometimes, the program tests the module, but sometimes it does something useful.
Flask()
is the constructor for the app object, which
is the main organizing part of our program: our app.
The Flask module has lots of decorators, even as it has discarded before_first_request
.
Sorry. I've fixed that now.
Sure. Let's look at the template file
We will almost never put HTML in our app.py files. That was baby steps before we get to the real stuff.
Yes, it's inside the brackets. It tells Flask to convert the string to an int.
I'm so glad! It was labor intensive, so I'm happy that it helped you.