I need to check the variable's case like if it is in upper case or lower case. Can we do that in Django template ?
1
-
You can write your own filter or template tag to do it! – Rajesh Yogeshwar Feb 10 '17 at 6:31
Add a comment
|
Use the upper
test provided by Jinja.
{% if variable is upper %}Yes, the variable is uppercase!{% endif %}
If you are sure that variable will be a string, you can use isupper
method of string to check if string is in uppercase or not. Similarly, islower
for checking lowercase.
@agaust. Thanks for edit, the builtin functions skipped my mind.
-
isupper() I can use only in Python Script not in Tag. Correct me if I am wrong. – Anurag Choudhary Feb 10 '17 at 9:22
-
1You can, for eg. in template {% if variable.isupper %} Then show it {% endif %} – Rajesh Yogeshwar Feb 10 '17 at 9:53