P
P
Pavel2017-08-23 15:36:39
Django
Pavel, 2017-08-23 15:36:39

Why can't ifequal be processed in the template after the form is submitted?

View template:

<select name="period" >
  {%for p in periods%}
  <option value="{{p.id}}" {%ifequal p.id form.period.value%}selected{%endifequal%}>{{p.name}}</option>
  {%endfor%}
</select>

When the field is displayed for the first time, when the data in the form is filled through "initial", then the condition is met and the "selected" attribute is successfully added. When the form is sent and the form is filled via Form(request.POST), the condition is no longer fulfilled. However, if you do this:
<select name="period" >
  {%for p in periods%}
  <option value="{{p.id}}">'{{p.id}}'{%if p.id == form.period.value%}equals{%else%}not equal{%endif%}'{{form.period.value}}'</option>
  {%endfor%}
</select>

then the result appears: '10' not equal '10'
Why can this happen?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question