[PYTHON] Flask HTML template settings

Introduction

This section describes how to create a Flask HTML template file.

Embedding variables and functions in HTML files

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 ...)%}.

Display record list

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 %}

View individual records

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>

Summary

Here, we explained the basics of creating HTML templates for Flask. Next time, I'll cover template inheritance and custom tag creation.

Recommended Posts

Flask HTML template settings
Flask initial settings
Django HTML Template # 2
Flask application settings
Django HTML template
Flask reuse How to write html
flask
flask
template
Flask initial settings
Flask application settings
Flask HTML template settings
flask
flask
(For myself) Flask_7 (Open database from Flask)
First Flask
samba settings
Flask memo
VIM settings