diff --git a/docs/Flask/04_templating__jinja2_integration_.md b/docs/Flask/04_templating__jinja2_integration_.md index 5d81d0c..f672140 100644 --- a/docs/Flask/04_templating__jinja2_integration_.md +++ b/docs/Flask/04_templating__jinja2_integration_.md @@ -110,8 +110,10 @@ Jinja2 offers more than just variable substitution. You can use basic programmin There are two main types of delimiters: +{% raw %} * `{{ ... }}`: Used for **expressions**. This is where you put variables you want to display, or even simple calculations or function calls. The result is inserted into the HTML. * `{% ... %}`: Used for **statements**. This includes things like `if`/`else` blocks, `for` loops, and other control structures. These don't directly output text but control how the template is rendered. +{% endraw %} Let's look at some examples. @@ -158,10 +160,12 @@ def profile(): **Explanation:** +{% raw %} * `{% if user and user.is_logged_in %}`: Starts an `if` block. Jinja2 checks if the `user` variable exists and if its `is_logged_in` attribute is true. * `{% else %}`: If the `if` condition is false, the code under `else` is used. * `{% endif %}`: Marks the end of the `if` block. * `{{ user.name }}`: Accesses the `name` attribute of the `user` dictionary passed from Python. +{% endraw %} If you run this and visit `/profile`, you'll see the "Welcome back, Charlie!" message. If you change `current_user` to `None` in the Python code and refresh, you'll see the "Welcome, Guest!" message. @@ -206,10 +210,12 @@ def show_items(): **Explanation:** +{% raw %} * `{% for fruit in items %}`: Starts a `for` loop. It iterates over the `items` list passed from Python. In each iteration, the current item is assigned to the variable `fruit`. * `