In the expression of Jinja2 template used in Python, learn how to replace the type with a number or letter.
# Jinja2 Numeric Character Type Conversion Method
To change a character to a numeric type first The variable myNum below takes the form of a number but is saved as a letter and cannot be used for comparison. If you change the type, you can use it for comparison. Here's how to change to the lower number type:

{{ 변수 | int }}

That is, you can add an int, the type you want to replace with the | symbol. So let's take a quick example.


! Jinja2 Numeric Transformation Example
A method to print the phrase "okay" only when you are over 10.
<div>
  {% if myNum|int > 10 %}
    <span>Okay</span>
  {% endif %}
</div>

myNum의 타입을 int인 숫자로 바꾸고 비교문을 사용하였습니다. 10이 넘는 경우에만 Okay를 출력할 것입니다.


! Example of converting Jinja2 characters
This time, it's a way to change the number-crossed data type. The grammar is as follows.

{{ variable| str }}

It's also used a lot of times to change. In particular, it is often used to print values that have been crossed over into letters to print them on the screen. Let me give you a quick example this time...
<div>
{% if muNum > 1000 %}
  Thank you. {{ myNum | str }} time(s) visited.
{% endif %}
</div>

In this example, if myNum variable is over 1000, the screen will print the corresponding value along with the phrase.


So that's where we looked at the number character type conversion in Jinja2.