jinja basics

This commit is contained in:
2024-10-10 10:08:42 +02:00
parent ab1187f3c4
commit 65a0b3cbab
4 changed files with 40 additions and 2 deletions

Binary file not shown.

View File

@ -19,4 +19,8 @@ def index():
@app.route('/user/<name>')
def user(name):
return "<h1>Hello {}!!!</h1>".format(name)
stuff = "This is some <strong> bold </strong> text"
liste = [1,2,3,4,5]
return render_template('user.html', name=name,
stuff=stuff,
liste=liste)

View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<title>Main</title>
</head>
<body>
<h1>Hello World</h1>

34
templates/user.html Normal file
View File

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{name | capitalize}}'s page</title>
</head>
<body>
<h1>Hello {{name | upper}}!!</h1> <!--This makes the whole thing capitalised-->
<h1>Hello {{name | capitalize}}!!</h1> <!--This makes the first char capitalised-->
<h1>Hello {{name | lower}}!!</h1>
<h1>Hello {{name | title}}!!</h1>
<p>{{ stuff }}</p>
<p>{{ stuff | safe }}</p> <!--This will allow html codes to be loaded-->
<p>{{ stuff | striptags }}</p> <!--This will remove html tags from the string-->
{% for item in liste %}
{% if item == 3 %}
<p>Thiiiiiiiiis is number THREEEEEEEEE!!!!</p>
{% else %}
<p style="font-size: 5ch; font-style: oblique; color: chocolate;">{{ item }}</p>
{% endif %}
{% endfor %}
<h1>Sahe thing with some math!</h1>
{% for item in liste %}
<p style="font-size: 5ch; font-style: oblique; color: chocolate;">{{ item **25 }}</p>
{% endfor %}
<p>The last element of my list is: {{liste[4]}}</p>
</body>
</html>