Quiz

  1. Why do we need to activate and deactivate a virtual environment?

    We will be installing Flask and PyMySQL and other Python packages to use in this course. Those packages are installed into a virtual environment (venv). The usual Python command only searches the system directories, so it won't "see" the packages we install. When we activate a venv, we get a Python that is configured to find our installed packages.

    I almost never deactivate. When I'm done, I just logout. But if I wanted to return to the normal Python (in that terminal) or activate a different python, I do use deactivate.

  2. What is a good way to keep all of the files from different tiers organized?

    It's a little complicated, isn't it? That was one of my first objections to using Flask: knowing where everything is.

    But I found that I quickly got used to it, and you will too.

    For now:

                folder
                    app.py
                    helper.py
                    templates/
                        home.html
                        profile.html            
                    static/
                        style.css
            
  3. How can Flask decide which function to call when multiple routes look similar?

    There's a definite algorithm that would breaks ties and such, but I've never found it to be confusing. In practice, we name the endpoints in distinctive ways, so that it's clear which one is wanted.

  4. Could you explain a little about decorators? What is "app" in the app.route() function?

    The app object is an instance of the Flask class. The route is a method that takes two arguments: a specification of an endpoint and a function definition, and it squirrels away the pair in a mapping that is used to look up the function to handle requests that match that endpoint.

    Decorators are a Python syntax that allows you to define a function but then "wrap up" the function inside another context.

  5. You mentioned this version of the course focuses more on Flask and the other on Node, what does that mean?

    Node.js is JavaScript running on the server, analogous to Python.

    Express is a JavaScript package, analogous to Flask. It provides middleware to help build web applications.

    The fall version of CS 304 focuses on Python/Flask, while the spring version focuses on Node/Express.

  6. No questions, thank you!