Determine variable type within django template

前端 未结 5 1104
执念已碎
执念已碎 2020-12-03 21:02

I have a variable that I\'m pulling into a table that sometimes is a date and sometimes is a string. If the variable is a date, I want to change the formatting:

<         


        
5条回答
  •  萌比男神i
    2020-12-03 21:52

    You can try this to recognize String vs List type:

    {%if v_1.0.1|length == 0%}
        
        {{v_1}}
    {%else%}     
                                                    
        {{v_1.0}}
    {%endif%}
    

提交回复
热议问题