Quiz

  1. could you please go over how to loop through get_flashed_messages() in jinja?

    Sure. It's the same as any loop:

    
        <ol>
            {% for msg in get_flashed_messages() %}
            <li> {{ msg }} </li>
            {% endfor %}
        </ol>
    
    
  2. For question 2, the directory technically has a CSS file within it, but not as a direct child (a grandchild). Is the question asking about direct children or if it's contained in the directory?

    I was thinking of it as the larger containment, rather than the narrower. But I can see that this is ambiguous. I'll ask LTS about how I can adjust the grading.

  3. Is it possible to specify a different CSS file for a child template? If so, how?

    Sure. The parent should have a block in the HEAD that the child can replace, putting an additional or different CSS file in there. (It's in the HEAD because that's where any LINK tags to external CSS files is supposed to be.)

    If the child also wants to replace some content in the BODY, that's okay too. Just replace two blocks.

    Parent:

    
        <!doctype html>
        <html>
        <head>
            <link href="{{url_for('static', file='main.css')}}">
            {% block headstuff %}
            {% endblock %}
        </head>
        <body>
            {% block main %}
            <p>some content</p>
            {% endblock %}
        </body>
        </html>
    
    

    And the child:

    
        {% extends "base.html" %}
        {% block headstuff %}
            <link href="{{url_for('static', file='extra.css')}}">
        {% endblock %}
        {% block main %}
        <!-- foo is defined in extra.css -->
        <p class="foo">And now for something completely different...</p>
        {% endblock %}
    
    
  4. So when using template inheritance, how can a child template keep the content from a parent block while also adding its own content, instead of completely replacing the block?

    Interesting. There is a variable called super that you can use, which is the inherited content:

    
        {% block main %}
        {{ super }}
        <P>And another thing...</P>
        {% endblock main %}
    
    

    I'd forgotten about this, probably because I've never used it. But I can see how it would be useful at times.

    See super blocks

  5. Not really a question but before this course I've tried using 11ty to manage static pages and the way we're working with template files reminds me of that but contrasting it with Flask makes me appreciate how cool dynamic page generation is.

    Very interesting!