Introduction to the function of Django Framework template
This article introduces the knowledge of "introduction to the function of Django framework template". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Definition: in the Django framework, templates are tools that help developers quickly generate pages that are presented to users
The design of the template realizes the decoupling of VT in our MVT. VT has the relationship of NVR M, a V can call any T, and a T can be used by any V.
Template processing is divided into two processes.
① loading
② rendering
The template has two main parts.
① HTML static code
Code snippets dynamically inserted by ② (digging, filling)
In addition to the basic static filling, the dynamic code snippets in the template can also achieve some basic operations, transformations and logic.
Variables in the template: data passed from the view to the template, following the rules for identifiers
Syntax {{var}}
Labels in templat
Syntax {tag}
Action
Load externally incoming variables
Create text in the output
Control loop or logic
{% if expression%} statement {% endif%} {% if expression%} statement {% else%} statement {% endif%} {% if expression%} statement {% elif expression%} statement {% endif%} {% for variable in list%} statement 1 {% empty%} statement 2 {% endfor%}
There are two kinds of template language annotations:
1 single-line comment: {# commented out #}
2 multiline comment
{% comment%}
What is annotated
{% endcomment%}
This is the end of the introduction to the function of Django Framework template. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!