analitics

Pages

Friday, August 9, 2019

Python 3.7.3 : Using the flask - part 013.

Flask uses Jinga2 template engine.
The Jinga2 template engine uses the following delimiters for escaping from HTML.
We can use this:
  • {% ... %} for Statements
  • {{ ... }} for Expressions to print to the template output
  • {# ... #} for Comments not included in the template output
  • # ... ## for Line Statements
The documentation webpage comes with all information about how can be used.
I create a new HTML5 file named layout.html and I will use this like an example:
{% if current_user.is_authenticated %}
...
{% else %}
...
{% endif %}
This file can be add into another file like this:
{% extends "layout.html" %}
{% block content %}
...
{% endblock content %}
For example, my about.html webpage comes with this source code:
{% extends "layout.html" %}
{% block content %}
    

About Page

{% endblock content %}
The routes.py this webpage will have this call:
@app.route("/about")
def about():
    return render_template('about.html', title='About')
In this way, I will add more HTML5 files to the project.