jinja basics
This commit is contained in:
Binary file not shown.
6
begin.py
6
begin.py
@ -19,4 +19,8 @@ def index():
|
|||||||
@app.route('/user/<name>')
|
@app.route('/user/<name>')
|
||||||
|
|
||||||
def 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)
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Document</title>
|
<title>Main</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Hello World</h1>
|
<h1>Hello World</h1>
|
||||||
|
34
templates/user.html
Normal file
34
templates/user.html
Normal 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>
|
Reference in New Issue
Block a user