244boy 244boy - 3 years ago 162
Python Question

Is there a simple method to make it as `""` instead of `None` in the template input?

In the template use the

{{ data.user_data.id_card }}
to show the value, but I get the
None
in it:

enter image description here

Is there a simple method to make it as
""
instead of
None
in the input?

Because I think use the
{% if %}
is too trouble, and not concise in my code.

If there is a template-filter method I can use?

Answer Source

Use default_if_none to replace None values in template.

{{ data.user_data.id_card|default_if_none:"" }}

Use default to replace empty strings in template.

{{ data.user_data.id_card|default:"Nothing" }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download