user1050619
user1050619

Reputation: 20896

Invalid block tag: 'phone_nos', expected 'endblock'

I have pass a list of phone nos in my view through the context object and use it in a HTML select box.

If the phones_nos list is empty I want to display a message but for some reason im unable to check if the phone_nos list is empty of not in the template.

We are using Django==1.6

Template:-

context = {
                   'phone_nos': [user.number for user in TwilioSMSDevice.objects.filter(user_id=User.objects.get(username=request.user).id)]                           
                }                        
                return TemplateResponse(request, self.index_template or
                                    'two_factor_auth.html', context)

<div class="form-row">    
    <label for="id-phone-number" class="required">Pick your Device:</label> 
    <!-- <input type="text" id="id-phone-number">     -->
    if {% phone_nos %}      
      <select id="id-phone-number">        
          {% for element in phone_nos %}
              <option value={{ element }}>{{ element }}</option>
          {% endfor %}
      </select>
    {% else %}
      In the else
    {% endif %}

  </div>

Error:-

Invalid block tag: 'phone_nos', expected 'endblock'

Upvotes: 0

Views: 192

Answers (1)

nthall
nthall

Reputation: 2915

The keyword if belongs inside the template tag, rather than preceding it:

{% if phone_nos %}

(side note: django 1.6 is no longer supported and considered insecure, please consider upgrading)

Upvotes: 2

Related Questions