This section describes how to create a Flask HTML template file.
In the HTML file, you can use {{variable name}}
to embed the variable passed from the view function in the HTML file.
You can also control the display contents using a function by setting {% function name (argument 1 argument 2 ...)%}
.
Extract the record list one by one using {% for%}
and display it.
app/samplemodel_list.html
{% for sample in table %}
<h1>{{ sample[char_sample] }}</h1>
<p>{{ sample[text_sample] }}</p>
{% endfor %}
Individual records can be displayed by using table name [column name]
.
app/samplemodel_detail.html
<h1>{{ sample[char_sample] }}</h1>
<p>{{ sample[text_sample] }}</p>
Here, we explained the basics of creating HTML templates for Flask. Next time, I'll cover template inheritance and custom tag creation.
Recommended Posts