• Could you walk through the big picture again, like how mypysql, flask, http, apache all work with each other?

    Sure, I'd be glad to.

  • Could I get a sentence to put all these topics together? Like how do static pages relate to templates, and how do HTTP methods and URL building relate in the whole picture?

    Here's one longish sentence:

    A browser requests a page from the server, and the server responds to that request either with a fixed, unchanging (static) page such as an "about" page, or with a dynamically computed page, such as the latest updates on a social media site.

    Templates are the static parts of a dynamic page. If I have some python code like this:

    
    def square_root_page(num):
        tmpl = '<p>the number was {x} and its square root is {y}</p>'
        print(tmpl.format(x=num, y=sqrt(num))
    
    
    The tmpl is actually a constant, static part of the printed result, while the num1 is dynamic.

    Now, imagine the tmpl being a 200 line HTML file. You'd much rather put that in a file. So it becomes a template file.

  • I'm confused by templates. I still don't really understand why templates are useful. Also, for the examples, I understand that the functions are using the corresponding templates, but I'm unsure as to what the functions are trying to accomplish.

    The template provides the static parts of the response.

  • Can you go over static files and templates with variables? When using render_template are we creating the static file?

    the tmpl above is a template with two variables (fillable areas). In Jinja2, we create files with as many fillable areas as we want.

    the render_template is not creating the file. It is filling in the fillable areas and creating a page to send to the browser.

  • I don't think I understand what a static webpage is - how do I know if my html file is static or not?

    The template file is always static. If there are no dynamic parts, then the page is static.

    A web page also has supporting files, like CSS files, JS files, images like logos and background images. Those are all static.

  • Does the url_for() method have to point to a specific file or folder to work properly?

    It points to a function! The function that generates the response for that URL.

  • Are all functions for urls located in one python file?

    In bigger, fancier Flask applications, they can be divided up. In our course, at least for now, they will all be in app.py.

  • What do you mean by 'always' use redirect(url_for())? Should we use it in the place of render_template()?

    I mean don't do redirect('/nm'+val).

    Do use either render_template OR redirect(url_for(function_name)).

  • Retrieving POST data is "getting" data using request.form but different from retrieving GET data (request.args)? Why doesn't GET retrieve the POST data?

    The word "get" is being overworked. GET is a format for a request. POST is the other. They are mutually exclusive. That means that a request is either sent using GET or POST. Never both. Postcards versus Envelopes.

    The flask app gets the request.

    Both of those things are dictionaries.

    To extract information from a dictionary, you can use dict[key] or dict.get(key). The latter is an entirely different get.

  • What is caching and why does it matter that POST doesn't cache? What are line statements (delimited by # ... ##)?

    Caching is when something that has been computed or retrieved is saved in case it's needed again. With POST, since it represents an update, we don't want the prior data, we want new data.

  • What are line statements (delimited by # ... ##)?

    An alternative for {% %}. We won't use them, so ignore this.