django模版中比较字符串和整型

    {% if user.id = user_id|add:0 %}Hello, User ID: {{ user_id }}{% endif %}

Sometimes you need to compare the ID/PK of an object with some value that comes from db, form field, etc., but they aren’t both integers and comparison fails.

A good way to solve this problem is adding zero to the string element using the filteradd, then Django will convert to integer first.

django模版中比较字符串和整型

相关文章:

你感兴趣的文章:

标签云: