How to convert string to uppercase / lowercase in Jinja2?

前端 未结 3 931
我寻月下人不归
我寻月下人不归 2020-12-25 09:56

I am trying to convert to upper case a string in a Jinja template I am working on.

In the template documentation, I read:

upper(s)
    Convert a valu         


        
相关标签:
3条回答
  • 2020-12-25 10:02

    And you can use: Filter like this

    {% filter upper %}
        UPPERCASE
    {% endfilter %}
    
    0 讨论(0)
  • 2020-12-25 10:03

    for the capitalize

    {{ 'helLo WOrlD'|capitalize }}
    

    output

    Hello world
    

    for the uppercase

    {{ 'helLo WOrlD'|upper }}
    

    output

    HELLO WORLD
    
    0 讨论(0)
  • 2020-12-25 10:11

    Filters are used with the |filter syntax:

    {% elif  student.department|upper != "MATHS DEPARTMENT" %}
        Maths department
    {% endif %}
    

    or you can use the str.upper() method:

    {% elif  student.department.upper() != "MATHS DEPARTMENT" %}
        Maths department
    {% endif %}
    

    Jinja syntax is Python-like, not actual Python. :-)

    0 讨论(0)
提交回复
热议问题