Skip to content
Advertisement

Django: How to apply conditional attribute to HTML element in template?

I have a checkbox in my Django jinja template. I want that checkbox to be checked if object boolean field is True.

My html element looks like:

JavaScript

The problem is, checkbox is still checked when attribute checked="False", it’s becomes unchecked only when the checked attribute is not there.

So what i need is, put checked attribute into the html element only if customer.SendSms is true.

I know something like

JavaScript

possible but this does not look so pretty, is there any other good way to handle this?

Advertisement

Answer

yesno template filter will do the job:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement