I tried integer zero in a input field (IntegerField), however that zero never appears to be show after submit.
This is part of my template:
{{user_date_table.june_11}}
{% if not user_date_table.june_11_steps %}
<form action="/steps_count/index/{{ username }}/table/" method="post">
{% csrf_token %}
<input type="text" autocorrect="off" autocapitalize="off" name="june_11_steps"/>
<input type="submit" value="Add"/>
</form>
{% else %}
{{user_date_table.june_11_steps}}
{% endif %}
I think that if not user_date_table.june_11_steps throws “True”, i.e. it is blank if I use zero as input. Is this correct, and can I overcome this?
In python, all of the following are evaluated as
False:So,
user_date_table.june_11_stepsis 0, then{% if not user_date_table.june_11_steps %}will be evaluatedTrueand that block will be executed.UPDATE: For solution,
If
user_date_tabledo not take place in your context while you display the form, or if it is empty, you can usePass another value to your template, like
display_result, and use that to check which fieldset will be displayed.views.py:
template.html
But the first approach is always better.